test: harden v0.8.3 plan-mode trust-boundary tests + fix nested marker tracking

Merged
AN
6mo ago
+109-120

What does this PR do?

Fast-follow hardening from the v0.8.3 multi-model code review (GPT 5.4 + Gemini 3.1 Pro + Kimi K2.5 + MiniMax M2.7 + Claude). All reviewers' verdict on the shipped v0.8.3 was ship — would not have blocked; these are the non-blocking items they surfaced.

  • Fix nested-marker tracking (processor.ts). The v0.8.3 marker fix wrapped the reworded plan-no-tool warning in an inner // altimate_change block nested inside the outer plan-refusal block. script/upstream/analyze.ts findMarkers (lines 499–520) uses a single openBlock with no nesting stack, so the inner start clobbered the outer block and its end was dropped — the outer block fell out of marker tracking. It passed the strict CI gate (hunk-based) and the count balance, so it never failed the release, but it degraded upstream-bridge accuracy. The warning text is already inside the outer block, so removing the inner markers keeps the strict gate green (pure deletion) and restores correct tracking. (Gemini; verified against analyze.ts.)
  • Harden the behavioral trust-boundary tests. Replaced session: {} as any with a structurally valid { slug, time: { created } } and added an explicit Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE === false precondition, so a future flag flip fails loudly instead of throwing an opaque TypeError in Session.plan (and silently dropping the intended coverage). (Consensus of all 5 reviewers; Gemini rated MAJOR.)
  • Add an end-to-end SINK test. The existing tests proved the intermediate trustedReminderParts; this drives the result through the real system-array hoist and MessageV2.toModelMessages, asserting attacker text never reaches system and the hoisted reminder is not duplicated into the user role. (GPT.)
  • Make the wording-fix guards concept/synonym-tolerant (keeping the load-bearing negative too thin to act on guard) so legitimate copy improvements don't break the suite. (MiniMax.)
  • Rename a mislabeled source-regex test — it asserts the InsertRemindersResult type alias, not runtime behaviour. (MiniMax.)
  • Revert the plan.txt start-marker description edit — plan.txt is imported raw into the LLM prompt, so the added words were model-visible; the prose already documents the escape hatch. (Gemini.)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Test improvement

Issue for this PR

Closes #898

How did you verify your code works?

  • bun test test/session/plan-layer-e2e.test.ts test/skill/release-v0.8.3-adversarial.test.ts test/session/processor.test.ts test/session/system.test.ts test/provider/family.test.ts — 192 pass, 0 fail (incl. the new end-to-end sink test and flag preconditions).
  • bun test test/session/ test/skill/ test/provider/ — 1619 pass, 0 fail.
  • bun run typecheck — clean.
  • bun run script/upstream/analyze.ts --markers --base origin/main --strict — All custom code properly marked (confirms the nested-marker removal keeps the gate green and the outer block is no longer clobbered).
  • Verified the nesting is gone: processor.ts now has a single outer block (345→411), no inner markers.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (n/a — test/tooling only)
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective
  • New and existing unit tests pass locally with my changes

Summary by cubic

Hardened v0.8.3 plan‑mode trust boundary and added end‑to‑end sink coverage, while fixing nested marker tracking in processor.ts to restore accurate upstream markers. Also reverted the model‑visible plan.txt marker description to keep the prompt unchanged. Closes #898.

  • Bug Fixes

    • Removed nested inner // altimate_change markers around the plan‑no‑tool warning so script/upstream/analyze.ts correctly tracks the outer block.
    • Reverted plan.txt start‑marker description since the file is imported raw into the LLM prompt.
  • Test Improvements

    • Added an end‑to‑end sink test to ensure attacker text never reaches system and reminders aren’t duplicated into the user role.
    • Replaced session: {} as any with a valid { slug, time: { created } } and added a Flag.OPENCODE_EXPERIMENTAL_PLAN_MODE === false precondition to fail loudly on future flips.
    • Made wording‑fix guards concept/synonym‑tolerant and renamed the source‑regex test to reflect it asserts the InsertRemindersResult type alias.

Summary by CodeRabbit

  • Tests

    • Expanded safety and trust-boundary test coverage for plan-layer functionality, including edge cases and adversarial scenarios.
  • Chores

    • Removed internal directive comments and cleaned up code organization.
    • Updated prompt configuration to streamline internal directives.