ECC/tests/scripts
Affaan Mustafa 6319c7d309
fix: stability batch — hook stdin truncation, Codex exa TOML, Stop hook JSON, GateGuard repetition (#2227)
* fix(hooks): fail open on oversized stdin instead of echoing truncated JSON (#2222)

run-with-flags.js capped stdin at 1MB but every fallthrough path still
echoed the truncated string to stdout. The harness parses hook stdout as
JSON, got a document cut mid-stream, and blocked the tool call — so any
Edit/Write with a >1MB hook payload was permanently blocked by every
registered pre-write hook, before ECC_HOOK_PROFILE / ECC_DISABLED_HOOKS
gating could run.

- Exit 0 with empty stdout (no opinion) when the stdin cap trips, before
  any echo or gating logic.
- Flush stdout via write callback before process.exit: exiting right
  after stdout.write() dropped everything past the ~64KB pipe buffer,
  cutting even sub-cap pass-through payloads mid-JSON.

Regression tests cover the enabled, disabled, and missing-arg paths for
oversized payloads plus full echo of sub-cap >64KB payloads.

* fix(codex): stop emitting invalid exa url entry, align merge with connector policy (#2224)

The Codex MCP merge declared exa with a url key, but Codex's
[mcp_servers.*] TOML schema is stdio-only — the url key makes the
entire config.toml fail to load, bricking both the codex CLI and the
desktop app. Every install/update re-injected the line because the
urlEntry branch treated the broken entry as present.

- ECC_SERVERS now emits only the current default set per
  docs/MCP-CONNECTOR-POLICY.md: chrome-devtools (stdio, command/args).
  Retired servers (supabase, playwright, context7, exa, github, memory,
  sequential-thinking) are never re-emitted; existing user-managed
  entries are untouched.
- The merge now repairs the exact ECC-emitted broken form (url-only
  exa entry) on every run so re-running the installer fixes broken
  configs instead of preserving them. User stdio exa entries
  (command + mcp-remote) are left alone.
- check-codex-global-state.sh requires chrome-devtools instead of the
  retired set, and flags url-only exa entries with a repair hint.

Tests cover repair, re-run idempotence, stdio-entry preservation, and
no-retired-server emission in add, update, dry-run, and disabled modes.

* fix(hooks): never echo truncated stdin from Stop hooks (#2090)

Stop hooks follow the ECC pass-through convention (echo stdin on
stdout), but every echoing Stop hook capped stdin and echoed the capped
string. The Stop payload carries last_assistant_message, so a long
final assistant message produced a JSON document cut mid-stream on
stdout, which the harness reports as 'Stop hook error: JSON validation
failed' across the whole Stop chain.

Reproduced: a Stop payload with a >64KB last_assistant_message run
through run-with-flags + cost-tracker emitted exactly 65536 bytes of
invalid JSON (cost-tracker capped stdin at 64KB — far below realistic
Stop payloads).

- cost-tracker: raise the cap to 1MB (matching all other hooks) and
  suppress the pass-through echo when stdin was truncated.
- check-console-log, stop-format-typecheck, desktop-notify: suppress
  the echo when stdin was truncated; flush stdout before process.exit
  so sub-cap payloads are not cut at the ~64KB pipe buffer.
- All hooks keep exiting 0 (fail-open); diagnostics go to stderr.

New stop-hooks-stdout test asserts the contract for every registered
Stop hook: stdout is empty or valid JSON, exit code 0 — for realistic
100KB payloads and oversized >1MB payloads, via the production runner
and via direct invocation. Updated the old hooks.test.js case that
codified the truncated-echo behavior.

* fix(hooks): dampen GateGuard fact-force repetition in long sessions (#2142)

In long autonomous sessions the fact-force gate produced 10+
near-identical 'state facts -> blocked -> restate -> retry' blocks in
one context window, which measurably raises the odds of the model
collapsing into a degenerate single-token repetition loop.

- Track a per-session fact_force_denials counter in GateGuard state
  (merged max across concurrent writers, reset with the session, robust
  to malformed on-disk values).
- The first GATEGUARD_FACT_FORCE_FULL_DENIALS denials (default 3) keep
  the full four-fact block; later denials emit a condensed single-line
  message that carries the denial ordinal, so consecutive denials are
  structurally different and never textually identical.
- True retries of the same target remain allowed without re-prompting
  (unchanged). Destructive-Bash and routine-Bash gates are unchanged,
  as are the ECC_GATEGUARD=off / ECC_DISABLED_HOOKS escape hatches.

Eight new tests cover budget counting, condensed format, ordinal
advancement, retry pass-through, env tuning, malformed state, MultiEdit
dampening, and destructive-gate exemption.

* fix(hooks): keep security hooks able to block on oversized stdin (#2222)

Refine the truncation fail-open: instead of skipping the hook entirely,
the runner now suppresses only its own raw-echo when stdin was
truncated. The hook still executes and receives the truncated flag
(run() context / ECC_HOOK_INPUT_TRUNCATED), so config-protection keeps
blocking truncated protected-config payloads (its test requires exit 2)
while pass-through hooks fail open with empty stdout as before.

* style: apply repo formatter to touched hook files
2026-06-11 00:31:33 -04:00
..
auto-update.test.js test: normalize auto-update repo root expectation on windows 2026-04-29 21:01:27 -04:00
build-opencode.test.js fix: narrow npm publish surface to the module graph 2026-04-12 23:48:53 -07:00
catalog.test.js feat: add install catalog and project config autodetection 2026-03-27 05:56:39 -04:00
check-unicode-safety.test.js test(ci): regression coverage for newly-covered invisible code points 2026-05-18 21:20:36 -04:00
claw.test.js fix: stabilize windows hook and claw tests 2026-03-05 12:37:24 -08:00
codex-hooks.test.js fix: stability batch — hook stdin truncation, Codex exa TOML, Stop hook JSON, GateGuard repetition (#2227) 2026-06-11 00:31:33 -04:00
consult.test.js fix: tune machine learning workflow routing 2026-05-11 18:11:05 -04:00
control-pane.test.js feat: add dynamic workflow team orchestration surface 2026-06-04 21:45:13 +08:00
discussion-audit.test.js chore: gate canonical ECC release identity (#1991) 2026-05-19 06:42:17 -04:00
doctor.test.js feat: orchestration harness, selective install, observer improvements 2026-03-14 12:55:25 -07:00
ecc-dashboard.test.js fix: port hook session and dashboard safety fixes 2026-05-11 02:53:28 -04:00
ecc.test.js feat: add ECC2 local control pane (#2131) 2026-06-03 21:54:30 +08:00
gemini-adapt-agents.test.js feat: add gemini agent adapter 2026-04-08 15:38:49 -07:00
harness-audit.test.js feat: extend harness audit integration scoring (#1990) 2026-05-19 06:20:54 -04:00
install-apply.test.js feat(mcp): single-connector default set + connector policy (#2219) 2026-06-09 23:28:35 -04:00
install-plan.test.js fix: restore short Claude plugin slug and skill installs (#1712) 2026-05-11 02:10:36 -04:00
install-ps1.test.js fix: document supported claude hook install path 2026-04-12 23:29:45 -07:00
install-readme-clarity.test.js docs: align rules README install namespace 2026-05-15 02:07:43 -04:00
install-sh.test.js fix: document supported claude hook install path 2026-04-12 23:29:45 -07:00
instinct-cli-projects.test.js fix: surface legacy data warning in instinct-cli status (#2127) 2026-06-07 13:26:22 +08:00
list-installed.test.js feat: orchestration harness, selective install, observer improvements 2026-03-14 12:55:25 -07:00
loop-status.test.js fix: handle dotted reserved snapshot names 2026-04-30 12:25:14 -04:00
manual-hook-install-docs.test.js fix: document supported claude hook install path 2026-04-12 23:29:45 -07:00
npm-publish-surface.test.js fix: close install manifest packaging gaps (#2172) 2026-06-07 13:25:51 +08:00
observability-readiness.test.js security: add supply-chain IOC scanner (#1904) 2026-05-14 21:15:35 -04:00
openclaw-persona-forge-gacha.test.js fix: CI fixes, security audit, remotion skill, lead-intelligence, npm audit (#1039) 2026-03-31 15:08:55 -04:00
operator-readiness-dashboard.test.js docs: sync live native payments gate evidence 2026-05-19 23:25:38 -04:00
orchestrate-codex-worker.test.js fix: refresh orchestration follow-up after #414 (#430) 2026-03-16 14:29:28 -07:00
orchestration-status.test.js feat: orchestration harness, selective install, observer improvements 2026-03-14 12:55:25 -07:00
platform-audit.test.js docs: sync selected-target announcement gate (#2020) 2026-05-19 22:09:45 -04:00
post-bash-command-log.test.js fix: port safe ci cleanup from backlog 2026-04-01 16:09:54 -07:00
preview-pack-smoke.test.js Add preview pack smoke gate 2026-05-17 15:35:23 -04:00
release-approval-gate.test.js Add release approval gate 2026-05-19 18:18:54 -04:00
release-publish.test.js test: normalize release workflow line endings 2026-05-18 13:53:26 -04:00
release-video-suite.test.js chore: refresh suite count evidence (#2000) 2026-05-19 09:58:53 -04:00
release.test.js test(ecc2): normalize release workflow newlines 2026-04-29 17:31:01 -04:00
repair.test.js test: stabilize repair lifecycle on Windows 2026-05-18 03:48:51 -04:00
session-inspect.test.js Add PowerShell installer wrapper and update documentation (#532) 2026-03-16 13:35:17 -07:00
setup-package-manager.test.js test: cover setGlobal/setProject catch blocks and session-start main().catch 2026-02-13 09:55:00 -08:00
skill-create-output.test.js test: add 3 tests for stdin 1MB overflow and analyzePhase async method (round 87) 2026-02-13 12:42:20 -08:00
sync-ecc-to-codex.test.js fix: harden install and codex sync portability 2026-04-01 16:04:56 -07:00
trae-install.test.js fix: retire rules/zh from the always-loaded default rules install (#2170) 2026-06-07 13:25:56 +08:00
uninstall.test.js feat: salvage windows desktop e2e skill 2026-05-11 19:15:02 -04:00