Skip to content

test(0.2): adversarial filesystem suite + 0.1.x schema migration fixture (Tracks 9.9/9.11)#150

Open
pmclSF wants to merge 1 commit intomainfrom
feat/0.2-track9-hardening
Open

test(0.2): adversarial filesystem suite + 0.1.x schema migration fixture (Tracks 9.9/9.11)#150
pmclSF wants to merge 1 commit intomainfrom
feat/0.2-track9-hardening

Conversation

@pmclSF
Copy link
Copy Markdown
Owner

@pmclSF pmclSF commented May 3, 2026

Summary

Two Track 9 (engineering hardening) deliverables. Both are pure
test additions — no behavior changes — and both raise adopter-
trust posture against scenarios the existing suite didn't
exercise. Both are explicitly post-0.2.0-blocking per the plan
but are safe to land now since they're additive.

  • Track 9.9 — Adversarial filesystem suite. 8 new tests
    exercising the analyzer against deliberately weird filesystem
    inputs: binary file with .ts extension, oversize source, UTF-8
    BOM, NUL bytes, empty test file, nested .git directories, deep
    nesting, long filename.
  • Track 9.11 — Schema migration fixture. Hand-crafted 0.1.x-
    shape JSON fixture + 3 tests that load + migrate it through the
    current code, asserting data preservation and round-trip
    idempotency.

What changed

New files (additive only):

  • internal/analysis/adversarial_fs_test.go — 8 adversarial FS
    tests (one skipped on Windows due to path-length)
  • internal/models/testdata/snapshot_v0_1_x_legacy.json
    realistic 0.1.x snapshot fixture
  • internal/models/migrate_fixture_test.go — 3 fixture-driven
    migration tests

What's NOT covered (with rationale)

  • Symlink loops — behavior diverges across platforms (Linux
    follows; macOS errors; Windows may not have symlinks). Add
    per-platform tests when a real adopter hits one.
  • Permission-denied directories — hard to set up portably
    without root. Manual smoke confirms the walker silently skips.

These exclusions are documented in the test file's package
comment so future contributors know the boundary.

Test plan

  • go build ./... clean
  • go test ./internal/analysis/... — 8 new adversarial-FS
    tests pass + existing tests unaffected
  • go test ./internal/models/... — 3 new fixture tests +
    existing migrate tests all green
  • go test ./... — full suite green
  • make docs-verify passes

Plan tracker

Closes Track 9.9 + 9.11. Track 9 remaining: 9.1-9.6, 9.7
(truth-verify), 9.8 (docs-linkcheck), 9.10 (memory bench), 9.12
(field tier docs). Per the plan, all of Track 9 is explicitly
post-0.2.0-blocking; this PR is safe to land in either the 0.2.0
or 0.2.x window.

🤖 Generated with Claude Code

…ure (Tracks 9.9/9.11)

Two Track 9 (engineering hardening) deliverables. Both are pure
test additions — no behavior changes — and both raise the
adopter-trust posture against scenarios the existing test suite
didn't exercise.

Track 9.9 — Adversarial filesystem suite
  New `internal/analysis/adversarial_fs_test.go` exercises the
  analyzer against 8 deliberately weird filesystem inputs that
  real repositories surface but synthetic fixtures usually don't:
    - binary file with .ts extension (misnamed asset / compiled
      artifact)
    - oversize source file (~2MB; tests size-skip threshold)
    - UTF-8 BOM at file start (Windows-edited files)
    - NUL bytes mid-content (transpiler / minifier output)
    - 0-byte test file (developer commits before filling in)
    - nested .git directories (submodules) — load-bearing
      assertion that .git contents never leak into inventory
    - 50-level deep directory nesting (skipped on Windows due
      to path-length limits)
    - 180-char filename (long-but-legal, tests filesystem
      assumptions)

  Contract: every test asserts Analyze completes without panic /
  hang / OOM. Some tests additionally assert that legitimate
  inputs survive (binary-poisoned tree must not lose the real
  test file; nested .git contents must never leak).

  Skipped (out of scope, with rationale):
    - Symlink loops: behavior differs across platforms; add
      per-platform tests when an adopter hits one.
    - Permission-denied: hard to set up portably; manual smoke
      verifies the walker silently skips.

Track 9.11 — Schema migration fixture
  New `internal/models/testdata/snapshot_v0_1_x_legacy.json` —
  hand-crafted JSON snapshot in the shape that 0.1.x actually
  wrote: schema version field absent, no SignalV2 envelope, no
  UnitID on code units, simpler snapshotMeta.

  New `internal/models/migrate_fixture_test.go` with 3 tests:
    - LoadLegacyFixture — load via Unmarshal + migrate via
      MigrateSnapshotInPlace; assert SchemaVersion stamped,
      generatedAt backfilled, UnitIDs backfilled (incl. parent-
      qualified case), compatibilityNotes in Metadata
    - LegacyFixtureDataPreserved — every field present in fixture
      (frameworks, test files, signals) survives intact through
      migration
    - FixtureRoundTripsViaJSON — migrated snapshot can be
      re-serialized + re-loaded + re-migrated near-idempotently
      (regression guard for the byte-identical determinism
      contract that `terrain analyze --write-snapshot` depends
      on)

Verification: 8 adversarial-FS tests + 3 fixture migration tests
pass; full Go test suite green; no regression in existing tests;
make docs-verify clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Terrain AI Risk Review

Metric Value
AI surfaces 13
Eval scenarios 16
Impacted scenarios 0
Uncovered surfaces 13

Decision: PASS — AI surfaces are covered.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

[PASS] Terrain — Safe to merge

All changed code is well protected by existing tests.

Metric Value
Changed files 3 (0 source · 2 test)
Tests selected 2 of 774 (0% of suite)

Pre-existing issues (2)

  • internal/analysis/adversarial_fs_test.go [LOW] — [staticSkippedTest] 1 of 8 tests statically skipped (12%) in internal/analysis/adversarial_fs_test.go.
  • internal/analysis/adversarial_fs_test.go [LOW] — [fixtureFragilityHotspot] Fixture 'mustWriteAdversarial' is used by 8 tests across 1 files. A single change cascades widely.

Recommended tests

2 test(s) with exact coverage of 0 impacted unit(s).

Test Confidence Why
internal/analysis/adversarial_fs_test.go exact test file directly changed
internal/models/migrate_fixture_test.go exact test file directly changed

Limitations
  • No coverage artifacts provided; protection gaps reflect missing data, not measured absence. Provide --coverage to improve accuracy.
  • Mixed test cultures reduce cross-framework optimization confidence. Consider standardizing on fewer frameworks.

Generated by Terrain · terrain pr --json for machine-readable output

Targeted Test Results

Terrain selected 2 test(s) instead of the full suite.

  • Go tests: passed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant