Skip to content

BAD CODE™: replace the occurrence-authority string ratchet with AST semantics #839

Description

@flyingrobots

Classification

BAD CODE™ — structural test debt exposed by review of #838.

Problem

test/unit/scripts/entity-capture-type-assertion-ratchet.test.ts currently protects the occurrence-authority boundary with a literal source-substring assertion:

expect(occurrence).not.toContain("issued.subject === occurrence.subject");

Whitespace, parentheses, or reversing the equality operands can restore the forbidden semantic coupling without tripping that ratchet. The same test already imports the TypeScript compiler API, so a syntax-dependent text check is below the established structural-testing standard.

Required correction

  • Parse src/domain/api/EntityOccurrence.ts through the TypeScript AST.
  • Detect equality comparisons between issued.subject and occurrence.subject regardless of operand order, whitespace, or parenthesization.
  • Keep the existing prohibitions on hidden WeakMap authority and private comparison callbacks.
  • Remove the literal source-text assertion once the semantic check exists.

Acceptance

  • A regression fixture fails for issued.subject === occurrence.subject.
  • A regression fixture fails for occurrence.subject===issued.subject.
  • The current occurrence-owned authority implementation passes.
  • The focused ratchet test and npm run test:fast pass.

Related: #838.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:testingPrimary work area: testing.priority:asapImmediate release pressure.status:availableOpen and available for prioritization; not blocked or actively in progress.type:debtDebt, rot, or structural risk.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions