Skip to content

test: replace source-regex extraction contracts with behavioral assertions #1403

Closed

Description

@Astro-Han

The #1084 refactor wave itself left behind a cluster of *-extraction-contract.test.ts files (born 2026-07-16 – 07-20) that pin source-text layout, not behavior, via readFile + dozens of assert.match/assert.doesNotMatch regexes:

  • packages/runtime/src/__tests__/tool-runtime-extraction-contract.test.ts (95 regex assertions)
  • packages/runtime/src/__tests__/ai-sdk-compaction-extraction-contract.test.ts (66)
  • packages/core/src/__tests__/settings-extraction-contract.test.ts (28)
  • packages/runtime/src/__tests__/active-full-compact-extraction-contract.test.ts
  • packages/headless/src/__tests__/oracle-registry-workflow-contract.test.ts

A rename or reformat breaks them; a behavioral regression passes them. session-manager.test.ts:8491 similarly pins runtime-kernel.ts internals by slicing source text (indexOf('private async *runAgentTurn') → includes('new AiSdkFlow')).

Scope

Replace each with (a) typed assertions on the extracted collaborator's public interface and (b) the lane's behavioral tests; delete the regex layer. Keep genuinely defensive source guards — containment-guard-contract.test.ts exists to prevent re-definition of a retired predicate and is fine as-is.

Policy for new extraction PRs (effective immediately): upcoming sub-issue PRs under #1084 and the third-pass governance issue should not add new source-regex extraction contracts. Pin an extraction with typed interface assertions and behavior tests instead.

Direction discussion (maintainer input wanted)

apps/desktop/src/main/__tests__ has a larger pre-existing family (~45 behavioral/wiring tests fed by renderer-shell-source-helpers.ts) asserting renderer wiring by regex over source text. Migrating those is a bigger project with real trade-offs (some assert cross-process wiring that is genuinely awkward to execute). This issue proposes agreeing on a policy — no new source-regex behavior tests; migrate opportunistically when a pinned file is refactored — rather than a big-bang rewrite.

References

#1084 (second-pass governance; the wave that introduced the cluster).

Activity

  1. added
    enhancement
    on Jul 23, 2026
  2. Astro-Han commented on Jul 24, 2026

    @Astro-Han
    ContributorAuthor

    I plan to take the two #1381-adjacent runtime files listed here: tool-runtime-extraction-contract.test.ts and ai-sdk-compaction-extraction-contract.test.ts. I’ll replace their source-regex coverage with typed and behavioral contracts, and leave the other #1403 files untouched.

  3. Astro-Han commented on Aug 2, 2026

    @Astro-Han
    ContributorAuthor

    The five source-regex test files are gone: #1448 replaced two of them with typed behavioral coverage, #1727 removed the other three, and #1675 dropped the slice assertions in session-manager.test.ts. What remains is policy discussion, not actionable work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions