Skip to content

test(runtime): deduplicate backend fixtures - #4946

Merged
Astro-Han merged 1 commit into
apache:mainfrom
orangeCatDeveloper:test/deduplicate-backend-fixtures
Sep 7, 2026
Merged

test(runtime): deduplicate backend fixtures#4946
Astro-Han merged 1 commit into
apache:mainfrom
orangeCatDeveloper:test/deduplicate-backend-fixtures

Conversation

@orangeCatDeveloper

@orangeCatDeveloper orangeCatDeveloper commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Summary

ai-sdk-backend.test.ts carries 204 direct createTestAiSdkBackend call sites on origin/main; 195 of them repeat the same six fixture properties byte-for-byte (sessionId: 'session-1', header: header(), appendMessage: async () => {}, apiKey: 'sk-test', newId: idGenerator(), now: monotonicClock()). A suite-local createBackend wrapper supplies those defaults once; the 195 eligible calls now pass only scenario-specific input, and a final spread keeps explicit overrides authoritative.

Result: the backend fixture now exists once instead of 195 times — net −1058 lines (17,373 → 16,315), runtime test count matches origin/main's suite (232 pass / 0 fail, before and after), test-name inventory byte-identical to origin/main's source (219 test() sites, including both parameterized loops), no test deleted, no assertion or scenario value changed.

The remaining createTestAiSdkBackend constructions are intentionally untouched: 9 direct call sites — 8 that deliberately rely on the constructor's internal defaults by omitting apiKey and/or newId/now/appendMessage (including the 4 Codex checkpoint calls), and 1 whose input spreads a dynamically built object — plus the internals of 3 suite helpers (imageReplayBackend, the durable replay helper, and createBackend itself), which already centralize their own defaults.

Rebased onto current origin/main (554b86445): conflicts with #4958 and #4951 were resolved by keeping main's parameterized tests (inheritedDenial × false/true, output × text/tool) and migrating their fixture calls to createBackend; main's newly added eligible call sites were migrated in the same sweep.

Part of the 2026-09 scavenger sweep T1 claim; plan and measured targets in #4945. A follow-up consolidation PR (#4945 stage 2) lands after this one merges.

Refs #4945

Verification

  • npm --workspace @maka/runtime run build
  • node --test --test-reporter=tap packages/runtime/dist/__tests__/ai-sdk-backend.test.js232 pass / 0 fail before and after; test-name inventory (219 test() sites) is byte-identical to origin/main's source (sorted diff empty)
  • npm --workspace @maka/runtime run typecheck
  • biome format / biome lint on the target → no fixes needed; git diff --check clean
  • Input preservation: every removed property line is byte-identical to a default the wrapper re-supplies ahead of its spread, so each migrated input expands to the original input; verified per call site (each of the 195 migrated sites lost exactly its six expected default lines; the 9 exempt direct calls and 2 helper internals are byte-identical to origin/main)

Before/after (one representative site):

// before
const backend = createTestAiSdkBackend({
  sessionId: 'session-1',
  header: header(),
  appendMessage: async () => {},
  connection: connection(),
  apiKey: 'sk-test',
  modelId: 'mock-model-id',
  modelFactory: () => completionModel(),
  tools: [],
  newId: idGenerator(),
  now: monotonicClock(),
});

// after
const backend = createBackend({
  connection: connection(),
  modelId: 'mock-model-id',
  modelFactory: () => completionModel(),
  tools: [],
});

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude (via pi coding agent) implemented the migration as a source codemod with per-call input-preservation assertions, rebased the PR onto updated origin/main (resolving the #4958/#4951 parameterized-test conflicts by keeping main's tests and migrating their fixture calls), migrated the newly added eligible call sites, ran the verification commands, and refreshed this description. The affected commit carries a Generated-by trailer.

Checklist

Does this PR entail a change in behavior?

  • No

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head db0cd4dce90f0f8fe22713027977b15340a2baec.

This is a test-only fixture refactor in packages/runtime/src/__tests__/ai-sdk-backend.test.ts. The suite-local createBackend wrapper at :15453-15467 supplies the six repeated defaults and spreads each scenario input afterward, so explicit overrides remain authoritative. I independently compared the old and new source: the test leaf-name set is unchanged, the 196 constructor sites become 181 wrapper calls plus the 15 intentionally specialized direct calls, and no migrated site retains a non-default value for a supplied key.

I found no P0-P3 correctness, ownership, concurrency, or test-integrity issue. The exact-head label and test checks passed; the merge-tree against current origin/main and diff check are clean, and changed-file Biome checking passed. The local worktree has no usable TypeScript compiler or built dist, so I did not independently run the runtime test file or typecheck locally.

Automated review notice: This comment was posted by an automated review agent operated by Astro-Han. It is not an independent human review and does not replace one.

@orangeCatDeveloper
orangeCatDeveloper force-pushed the test/deduplicate-backend-fixtures branch 2 times, most recently from 5240480 to 2951f1b Compare September 7, 2026 09:00
195 of the suite's direct createTestAiSdkBackend call sites repeat the
same six fixture properties (sessionId, header, appendMessage, apiKey,
newId, now) byte-for-byte. A suite-local createBackend wrapper supplies
those defaults once and lets each call pass only its scenario-specific
input; a final spread keeps explicit overrides authoritative.

The remaining createTestAiSdkBackend constructions are intentionally
untouched: nine direct call sites (eight that deliberately rely on the
constructor's internal defaults by omitting apiKey and/or newId/now/
appendMessage, and one whose input spreads a dynamically built object)
plus the internals of three suite helpers (imageReplayBackend, the
durable replay helper, and createBackend itself), which already
centralize their own defaults.

Constructor inputs are preserved exactly: every removed property is
byte-identical to a default the wrapper supplies ahead of its spread,
so each migrated input expands to the original input, and migrated
call sites retain only scenario-specific keys. Test names, scenario
values, and assertions are unchanged: the test-name inventory (219
test() sites, including both parameterized loops) is byte-identical to
origin/main's source, and the suite passes 232/232.

Rebased onto current origin/main: conflicts with apache#4958 and apache#4951 were
resolved by keeping main's parameterized tests and migrating their
fixture calls to createBackend.

Generated-by: Claude (pi coding agent)
@orangeCatDeveloper
orangeCatDeveloper force-pushed the test/deduplicate-backend-fixtures branch from 2951f1b to 52d0c22 Compare September 7, 2026 09:21

@Astro-Han Astro-Han left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change. Approving exact head 52d0c22236482683163601382950fb742a738804 following the completed review and Astro-Han’s explicit acceptance of this merge batch. Current checks pass and no review threads remain unresolved.

Backend tests repeated the same fixture defaults at many call sites. Supply those defaults once in a suite-local helper, with explicit overrides last and specialized constructions preserved. No production behavior or test scenario is removed.

AI assistance: Codex performed the review and final-state verification; Astro-Han authorized approval and merge.

中文

感谢改动。基于已完成的审查和 Astro-Han 对本批次的明确认可,批准当前精确 head;检查通过,讨论已结清。此前说明的验证边界与后续事项保持不变。本次由 Codex 执行审查和状态核对,Astro-Han 授权批准与合并。

@Astro-Han
Astro-Han merged commit 8ea1158 into apache:main Sep 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/XL Under 2500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants