pi-harness-runtime 1.1.439 → 1.1.441
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/harness/e2e/auto-test-loop.ts +8 -2
- package/harness/e2e/browser-scrapers/base-browser-scraper.ts +2 -0
- package/harness/e2e/browser-scrapers/chrome-profile-manager.ts +2 -0
- package/harness/e2e/browser-scrapers/codex-browser-scraper.ts +2 -0
- package/harness/e2e/tools-detector.ts +2 -0
- package/harness/index.ts +2 -1
- package/harness/key-loader.ts +2 -0
- package/harness/langchain/checkpointer.ts +2 -0
- package/harness/langchain/cron-cli.ts +2 -0
- package/harness/langchain/graph.ts +2 -0
- package/harness/master-planner.ts +1 -1
- package/harness/notification-center.ts +2 -0
- package/harness/output-limit-handler.ts +1 -1
- package/harness/project-detector/detector.ts +2 -4
- package/harness/secret-provider.ts +2 -0
- package/harness/task-graph.ts +460 -113
- package/index.ts +16 -7
- package/package.json +7 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/agent-policy/dist/extension.d.ts.map +1 -1
- package/packages/agent-policy/dist/extension.js +2 -0
- package/packages/agent-policy/dist/extension.js.map +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/agent-policy/src/extension.ts +2 -0
- package/packages/architecture-generator/package.json +1 -1
- package/packages/auth/dist/minimax-browser-auth.d.ts.map +1 -1
- package/packages/auth/dist/minimax-browser-auth.js +23 -1
- package/packages/auth/dist/minimax-browser-auth.js.map +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/auth/src/minimax-browser-auth.ts +30 -5
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/autonomous-runtime/dist/inbox.d.ts.map +1 -1
- package/packages/autonomous-runtime/dist/inbox.js +2 -0
- package/packages/autonomous-runtime/dist/inbox.js.map +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/autonomous-runtime/src/inbox.ts +2 -0
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/clipboard/dist/src/clipboard.d.ts.map +1 -1
- package/packages/clipboard/dist/src/clipboard.js +2 -0
- package/packages/clipboard/dist/src/clipboard.js.map +1 -1
- package/packages/clipboard/dist/src/copy-sync.d.ts.map +1 -1
- package/packages/clipboard/dist/src/copy-sync.js +2 -0
- package/packages/clipboard/dist/src/copy-sync.js.map +1 -1
- package/packages/clipboard/dist/src/gist-relay.d.ts.map +1 -1
- package/packages/clipboard/dist/src/gist-relay.js +2 -0
- package/packages/clipboard/dist/src/gist-relay.js.map +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/clipboard/src/clipboard.ts +2 -0
- package/packages/clipboard/src/copy-sync.ts +2 -0
- package/packages/clipboard/src/gist-relay.ts +2 -0
- package/packages/clipboard-plugin/dist/types.d.ts +9 -2
- package/packages/clipboard-plugin/dist/types.d.ts.map +1 -1
- package/packages/clipboard-plugin/package.json +1 -1
- package/packages/clipboard-plugin/src/types.ts +9 -2
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/connection-runtime/package.json +1 -1
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-discovery/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/contracts/dist/delegation-store.js +1 -4
- package/packages/contracts/dist/workspace-env.js +28 -1
- package/packages/contracts/package.json +1 -1
- package/packages/contracts/src/delegation-store.ts +9 -4
- package/packages/contracts/src/workspace-env.ts +29 -4
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/dependency-analyzer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/durable-review/package.json +1 -1
- package/packages/e2e-tester/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-sink/package.json +1 -1
- package/packages/event-store/dist/src/store.d.ts.map +1 -1
- package/packages/event-store/dist/src/store.js +2 -0
- package/packages/event-store/dist/src/store.js.map +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/event-store/src/store.ts +3 -0
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/dist/analyzer.d.ts.map +1 -1
- package/packages/generic-web-plugin/dist/analyzer.js +2 -0
- package/packages/generic-web-plugin/dist/analyzer.js.map +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/generic-web-plugin/src/analyzer.ts +3 -0
- package/packages/health-monitor/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-graph/package.json +1 -1
- package/packages/knowledge-retrieval/dist/mcp-client.d.ts.map +1 -1
- package/packages/knowledge-retrieval/dist/mcp-client.js +0 -1
- package/packages/knowledge-retrieval/dist/mcp-client.js.map +1 -1
- package/packages/knowledge-retrieval/package.json +1 -4
- package/packages/knowledge-retrieval/src/mcp-client.ts +0 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/logging/package.json +1 -1
- package/packages/mcp-adapter/dist/server.d.ts.map +1 -1
- package/packages/mcp-adapter/dist/server.js +2 -0
- package/packages/mcp-adapter/dist/server.js.map +1 -1
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/mcp-adapter/src/server.ts +3 -0
- package/packages/memory-engine/package.json +1 -1
- package/packages/milestone-manager/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/observability/package.json +1 -1
- package/packages/okf-indexer/package.json +1 -1
- package/packages/paperclip-integration/dist/index.d.ts.map +1 -1
- package/packages/paperclip-integration/dist/index.js +2 -0
- package/packages/paperclip-integration/dist/index.js.map +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/paperclip-integration/src/index.ts +2 -0
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/permission-mode/package.json +1 -1
- package/packages/privilege-broker/dist/audit.d.ts.map +1 -1
- package/packages/privilege-broker/dist/audit.js +2 -0
- package/packages/privilege-broker/dist/audit.js.map +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/privilege-broker/src/audit.ts +2 -0
- package/packages/project-analyzer/package.json +1 -1
- package/packages/project-bootstrap/package.json +1 -1
- package/packages/projection-engine/package.json +1 -1
- package/packages/prompt-compiler/dist/compiler.d.ts.map +1 -1
- package/packages/prompt-compiler/dist/compiler.js +2 -0
- package/packages/prompt-compiler/dist/compiler.js.map +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-compiler/src/compiler.ts +2 -0
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/package.json +1 -1
- package/packages/scheduler-adapter/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/session-api/package.json +1 -1
- package/packages/session-export/package.json +1 -1
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-mcp-client/dist/client.d.ts.map +1 -1
- package/packages/skill-mcp-client/dist/client.js +0 -1
- package/packages/skill-mcp-client/dist/client.js.map +1 -1
- package/packages/skill-mcp-client/package.json +1 -4
- package/packages/skill-mcp-client/src/client.ts +0 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/skills/dist/parser.d.ts.map +1 -1
- package/packages/skills/dist/parser.js +2 -0
- package/packages/skills/dist/parser.js.map +1 -1
- package/packages/skills/dist/skill-versioning.d.ts.map +1 -1
- package/packages/skills/dist/skill-versioning.js +2 -0
- package/packages/skills/dist/skill-versioning.js.map +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/skills/src/parser.ts +3 -0
- package/packages/skills/src/skill-versioning.ts +2 -0
- package/packages/sprint-planner/package.json +1 -1
- package/packages/subscription-engine/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/tencentdb-memory/package.json +1 -1
- package/packages/tencentdb-sync/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/tooling-preference/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/two-phase-review/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/voice-api/package.json +1 -1
- package/packages/webmcp-tester/dist/index.js +0 -2
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/webmcp-tester/src/index.ts +0 -3
- package/packages/wiki/package.json +1 -1
- package/packages/workflow-events/package.json +1 -1
- package/packages/workspace-scanner/package.json +1 -1
- package/packages/worktree/package.json +1 -1
- package/packages/write-review/dist/trigger.d.ts.map +1 -1
- package/packages/write-review/dist/trigger.js +1 -2
- package/packages/write-review/dist/trigger.js.map +1 -1
- package/packages/write-review/package.json +1 -1
- package/packages/write-review/src/trigger.ts +1 -2
- package/scripts/lib/runtime-imports.ts +189 -3
- package/scripts/release-all.ts +5 -3
- package/scripts/telegram-webhook-server.ts +2 -0
- package/scripts/typecheck-packages.mjs +7 -4
- package/scripts/verify-package-contents.ts +161 -2
- package/harness/e2e/tools-detector.test.ts +0 -156
- package/harness/glm-quota-countdown.test.ts +0 -323
- package/harness/langchain/agents.test.ts +0 -39
- package/harness/langchain/checkpointer.test.ts +0 -243
- package/harness/langchain/daemon.test.ts +0 -459
- package/harness/langchain/model-router.test.ts +0 -191
- package/harness/langchain/ping-pong-middleware.test.ts +0 -69
- package/harness/langchain/scoreboard.test.ts +0 -245
- package/harness/langchain/status-line.test.ts +0 -106
- package/harness/langchain/surge.test.ts +0 -467
- package/harness/langchain/widget.test.ts +0 -251
- package/harness/skill-sync.test.ts +0 -57
- package/harness/ssh-detach-interceptor.test.ts +0 -263
- package/harness/ssh-hang-recovery.test.ts +0 -86
- package/packages/a2a-adapter/test/a2a.test.ts +0 -151
- package/packages/agent-policy/test/interlock.test.ts +0 -101
- package/packages/agent-policy/test/policy-retention.test.ts +0 -380
- package/packages/agent-policy/test/policy.test.ts +0 -387
- package/packages/auth/test/auth.test.ts +0 -238
- package/packages/autonomous-refactor/test/refactor.test.ts +0 -202
- package/packages/autonomous-runtime/test/types.test.ts +0 -95
- package/packages/cache-strategy/test/cache.test.ts +0 -137
- package/packages/capability-registry/test/registry.test.ts +0 -204
- package/packages/checkpoint/test/engine.test.ts +0 -265
- package/packages/cli-plugin-sdk/test/cli.test.ts +0 -45
- package/packages/code-generation/test/generator.test.ts +0 -238
- package/packages/code-review/test/engine.test.ts +0 -302
- package/packages/codex-adapter/test/provider.test.ts +0 -142
- package/packages/codex-watcher/test/watch.test.ts +0 -453
- package/packages/context-compiler/test/context-compiler.test.ts +0 -746
- package/packages/context-manager/test/context.test.ts +0 -198
- package/packages/contracts/test/delegation.test.ts +0 -350
- package/packages/contracts/test/workspace-env.test.ts +0 -802
- package/packages/cookie-sanitizer/test/infer.test.ts +0 -110
- package/packages/cookie-sanitizer/test/normalize.test.ts +0 -113
- package/packages/cookie-sanitizer/test/parse.test.ts +0 -204
- package/packages/cookie-sanitizer/test/sync.test.ts +0 -237
- package/packages/cookie-sanitizer/test/watcher.test.ts +0 -27
- package/packages/cost-optimizer/test/cost-optimizer.test.ts +0 -438
- package/packages/dependency-analyzer/test/analyzer.test.ts +0 -49
- package/packages/django-plugin/test/analyzer.test.ts +0 -195
- package/packages/doc-generator/test/docs.test.ts +0 -168
- package/packages/durable-review/test/acceptance.test.ts +0 -357
- package/packages/durable-review/test/smoke.test.ts +0 -107
- package/packages/evaluation-engine/test/engine.test.ts +0 -277
- package/packages/evaluation-runner/test/runner.test.ts +0 -168
- package/packages/event-bus/test/bus.test.ts +0 -100
- package/packages/event-store/test/store.test.ts +0 -115
- package/packages/experience-replay/test/replay.test.ts +0 -267
- package/packages/feedback-collector/test/collector.test.ts +0 -142
- package/packages/framework-detector/test/detector.test.ts +0 -75
- package/packages/framework-plugin-sdk/test/manager.test.ts +0 -320
- package/packages/frappe-plugin/test/analyzer.test.ts +0 -250
- package/packages/generic-web-plugin/test/analyzer.test.ts +0 -134
- package/packages/health-monitor/test/health.test.ts +0 -231
- package/packages/intent-analyzer/test/analyzer.test.ts +0 -72
- package/packages/intent-analyzer/test/ping-pong.test.ts +0 -96
- package/packages/jev-judge/tests/auto-continue-context.test.ts +0 -280
- package/packages/jev-judge/tests/continuation-controller.test.ts +0 -1396
- package/packages/jev-judge/tests/jev-provider-chain.test.ts +0 -536
- package/packages/jev-judge/tests/outcome-application.test.ts +0 -132
- package/packages/jev-judge/tests/question-risk.test.ts +0 -129
- package/packages/jev-judge/tests/typesafe-provider.test.ts +0 -640
- package/packages/jev-judge/tests/validation-ledger.test.ts +0 -181
- package/packages/jev-judge/tests/validation-plan.test.ts +0 -170
- package/packages/jev-judge/tests/validation-tie-breaker.test.ts +0 -88
- package/packages/laravel-plugin/test/analyzer.test.ts +0 -220
- package/packages/learning-engine/test/engine.test.ts +0 -331
- package/packages/logging/test/buffer.test.ts +0 -44
- package/packages/logging/test/classification.test.ts +0 -137
- package/packages/logging/test/config.test.ts +0 -97
- package/packages/logging/test/fanout.test.ts +0 -186
- package/packages/logging/test/identity-transport.test.ts +0 -197
- package/packages/logging/test/incidents.test.ts +0 -404
- package/packages/logging/test/ingest-schema.test.ts +0 -184
- package/packages/logging/test/integration.test.ts +0 -140
- package/packages/logging/test/log-http.test.ts +0 -246
- package/packages/logging/test/redact.test.ts +0 -109
- package/packages/logging/test/sampler.test.ts +0 -57
- package/packages/logging/test/server.test.ts +0 -444
- package/packages/logging/test/shipper.test.ts +0 -152
- package/packages/logging/test/spool.test.ts +0 -96
- package/packages/mcp-adapter/test/server.test.ts +0 -91
- package/packages/memory-engine/test/engine.test.ts +0 -456
- package/packages/model-registry/test/registry.test.ts +0 -342
- package/packages/nextjs-plugin/test/analyzer.test.ts +0 -149
- package/packages/notification/test/approval-payload.test.ts +0 -269
- package/packages/notification/test/detail-format.test.ts +0 -106
- package/packages/notification/test/notification.test.ts +0 -375
- package/packages/notification/test/pending-question-lifecycle.test.ts +0 -195
- package/packages/notification/test/pending-question.test.ts +0 -331
- package/packages/notification/test/tooling-proposal-payload.test.ts +0 -212
- package/packages/observability/test/observability.test.ts +0 -1350
- package/packages/performance-optimizer/test/optimizer.test.ts +0 -267
- package/packages/project-analyzer/test/index.test.ts +0 -1719
- package/packages/prompt-compiler/test/prompt-compiler.test.ts +0 -813
- package/packages/prompt-versioning/test/versioning.test.ts +0 -112
- package/packages/provider-adapter-sdk/test/sdk.test.ts +0 -220
- package/packages/provider-router/test/provider-router.test.ts +0 -405
- package/packages/provider-selector/test/selector.test.ts +0 -192
- package/packages/providers/test/providers.test.ts +0 -225
- package/packages/qdrant-skills/test/collection-info.test.ts +0 -165
- package/packages/qdrant-skills/test/embedder-batch.test.ts +0 -184
- package/packages/qdrant-skills/test/embedder.test.ts +0 -97
- package/packages/quota-manager/test/quota.test.ts +0 -432
- package/packages/rate-limiter/test/limiter.test.ts +0 -128
- package/packages/react-vite-plugin/test/analyzer.test.ts +0 -139
- package/packages/relay/test/client.test.ts +0 -446
- package/packages/relay/test/relay-e2e.test.ts +0 -299
- package/packages/relay/test/relay-endpoint.test.ts +0 -278
- package/packages/release-manager/test/release.test.ts +0 -215
- package/packages/requirement-compiler/test/requirement-compiler.test.ts +0 -743
- package/packages/runtime/test/runtime-api.test.ts +0 -169
- package/packages/runtime/test/runtime.test.ts +0 -297
- package/packages/scheduler/test/scheduler.test.ts +0 -125
- package/packages/session/test/manager.test.ts +0 -233
- package/packages/shared-context/test/shared-context.test.ts +0 -114
- package/packages/skill-registry/test/registry.test.ts +0 -508
- package/packages/skills/test/init-skills.test.ts +0 -114
- package/packages/skills/test/remote-skills.test.ts +0 -360
- package/packages/skills/test/remote-source.test.ts +0 -248
- package/packages/skills/test/sanitize.test.ts +0 -250
- package/packages/skills/test/vector-indexing.test.ts +0 -205
- package/packages/skills/test/vector-schema.test.ts +0 -180
- package/packages/skills/test/vector-threshold.test.ts +0 -108
- package/packages/sprint-planner/test/planner.test.ts +0 -187
- package/packages/task-compiler/test/task-compiler.test.ts +0 -628
- package/packages/test-data-generator/test/generator.test.ts +0 -265
- package/packages/test-generator/test/generator.test.ts +0 -156
- package/packages/token-estimation/test/token-estimation.test.ts +0 -207
- package/packages/token-optimizer/test/optimizer.test.ts +0 -141
- package/packages/tooling-preference/tests/changed-files.test.ts +0 -124
- package/packages/tooling-preference/tests/detect.test.ts +0 -188
- package/packages/tooling-preference/tests/proposal.test.ts +0 -107
- package/packages/tooling-preference/tests/quality-check.test.ts +0 -272
- package/packages/tooling-preference/tests/registry.test.ts +0 -51
- package/packages/tooling-preference/tests/store.test.ts +0 -99
- package/packages/trajectory/test/store.test.ts +0 -250
- package/packages/tui/test/harness-footer.test.ts +0 -559
- package/packages/tui/test/harness-header.test.ts +0 -590
- package/packages/two-phase-review/test/classify.test.ts +0 -102
- package/packages/two-phase-review/test/helpers.ts +0 -72
- package/packages/two-phase-review/test/rules.test.ts +0 -150
- package/packages/two-phase-review/test/runtime.test.ts +0 -362
- package/packages/two-phase-review/test/scope.test.ts +0 -186
- package/packages/two-phase-review/test/signals.test.ts +0 -183
- package/packages/two-phase-review/test/state.test.ts +0 -201
- package/packages/wiki/test/basic.test.ts +0 -242
- package/packages/workspace-scanner/test/scanner.test.ts +0 -43
- package/packages/worktree/test/worktree.test.ts +0 -163
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test helpers.
|
|
3
|
-
*
|
|
4
|
-
* The fixtures live inside the package, never in the shared `/tmp`: a full
|
|
5
|
-
* `bun test packages/` run is long enough that a temporary directory there
|
|
6
|
-
* can disappear while the test is still running.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
-
import { homedir } from "node:os";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
import { fileURLToPath } from "node:url";
|
|
13
|
-
|
|
14
|
-
const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
15
|
-
|
|
16
|
-
/** A fresh temporary directory inside the package. */
|
|
17
|
-
export function makeTempDir(prefix: string): string {
|
|
18
|
-
return mkdtempSync(join(PACKAGE_ROOT, `.test-${prefix}-`));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* A fresh temporary directory that belongs to no Git repository.
|
|
23
|
-
*
|
|
24
|
-
* The home directory is used because it is neither the shared `/tmp` nor part
|
|
25
|
-
* of the repository under test.
|
|
26
|
-
*/
|
|
27
|
-
export function makePlainTempDir(prefix: string): string {
|
|
28
|
-
return mkdtempSync(join(homedir(), `.test-${prefix}-`));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Run the body with a fresh temporary directory and remove it afterwards.
|
|
33
|
-
*
|
|
34
|
-
* The directory lives only inside the body, never in a variable that a hook
|
|
35
|
-
* could clean up at the wrong moment.
|
|
36
|
-
*/
|
|
37
|
-
export function withTempDir<T>(prefix: string, body: (dir: string) => T): T {
|
|
38
|
-
const dir = makeTempDir(prefix);
|
|
39
|
-
try {
|
|
40
|
-
return body(dir);
|
|
41
|
-
} finally {
|
|
42
|
-
rmSync(dir, { recursive: true, force: true });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** Run the body with a fresh directory outside every Git repository. */
|
|
47
|
-
export function withPlainTempDir<T>(prefix: string, body: (dir: string) => T): T {
|
|
48
|
-
const dir = makePlainTempDir(prefix);
|
|
49
|
-
try {
|
|
50
|
-
return body(dir);
|
|
51
|
-
} finally {
|
|
52
|
-
rmSync(dir, { recursive: true, force: true });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Run an asynchronous body with a fresh temporary directory.
|
|
58
|
-
*
|
|
59
|
-
* The directory only disappears after the body finished: a synchronous
|
|
60
|
-
* helper would remove it while the body is still running.
|
|
61
|
-
*/
|
|
62
|
-
export async function withTempDirAsync<T>(
|
|
63
|
-
prefix: string,
|
|
64
|
-
body: (dir: string) => Promise<T>,
|
|
65
|
-
): Promise<T> {
|
|
66
|
-
const dir = makeTempDir(prefix);
|
|
67
|
-
try {
|
|
68
|
-
return await body(dir);
|
|
69
|
-
} finally {
|
|
70
|
-
rmSync(dir, { recursive: true, force: true });
|
|
71
|
-
}
|
|
72
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The workflow rules.
|
|
3
|
-
*
|
|
4
|
-
* The injected instruction names the phase, the open work and the next step.
|
|
5
|
-
* It must never suggest to start the review while the implementation runs.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { describe, it, expect } from "bun:test";
|
|
9
|
-
import {
|
|
10
|
-
TWO_PHASE_CONTRACT,
|
|
11
|
-
buildChunkTodoSubject,
|
|
12
|
-
buildPhaseInstruction,
|
|
13
|
-
buildPhaseView,
|
|
14
|
-
buildReviewTodoDescription,
|
|
15
|
-
buildReviewTodoSubject,
|
|
16
|
-
isChunkTodo,
|
|
17
|
-
syncChunkStatus,
|
|
18
|
-
} from "../src/rules.js";
|
|
19
|
-
import { createState, recordSignal, startReview, transitionToReviewPending } from "../src/state.js";
|
|
20
|
-
import { REVIEW_PREFIX } from "../src/classify.js";
|
|
21
|
-
import type { ReviewChunk, ReviewSignal } from "../src/types.js";
|
|
22
|
-
|
|
23
|
-
const signal: ReviewSignal = {
|
|
24
|
-
source: "code-reviewer",
|
|
25
|
-
files: ["packages/notification/index.ts"],
|
|
26
|
-
reason: "a comprehensive review was requested with code-reviewer",
|
|
27
|
-
at: "2026-10-25T00:00:00.000Z",
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
describe("TWO_PHASE_CONTRACT", () => {
|
|
31
|
-
it("names the two phases", () => {
|
|
32
|
-
expect(TWO_PHASE_CONTRACT).toContain("Phase 1");
|
|
33
|
-
expect(TWO_PHASE_CONTRACT).toContain("Phase 2");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("keeps the correctness checks in the implementation", () => {
|
|
37
|
-
expect(TWO_PHASE_CONTRACT).toContain("type errors");
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("names the todo prefixes", () => {
|
|
41
|
-
expect(TWO_PHASE_CONTRACT).toContain("[IMPLEMENT]");
|
|
42
|
-
expect(TWO_PHASE_CONTRACT).toContain(REVIEW_PREFIX);
|
|
43
|
-
expect(TWO_PHASE_CONTRACT).toContain("[REVIEW-FIX]");
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe("buildPhaseInstruction", () => {
|
|
48
|
-
it("asks for the implementation while it runs", () => {
|
|
49
|
-
const state = createState("t");
|
|
50
|
-
const view = buildPhaseView(state, [
|
|
51
|
-
{ id: 1, subject: "Add the storage", status: "pending" },
|
|
52
|
-
]);
|
|
53
|
-
const instruction = buildPhaseInstruction(state, view);
|
|
54
|
-
expect(instruction).toContain("Phase 1");
|
|
55
|
-
expect(instruction).toContain("1 implementation todo(s) open");
|
|
56
|
-
expect(instruction).toContain("Do not start a comprehensive review");
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("does not start the review while a signal is queued", () => {
|
|
60
|
-
const state = recordSignal(createState("t"), signal);
|
|
61
|
-
const view = buildPhaseView(state, [
|
|
62
|
-
{ id: 1, subject: "Add the storage", status: "pending" },
|
|
63
|
-
]);
|
|
64
|
-
const instruction = buildPhaseInstruction(state, view);
|
|
65
|
-
expect(instruction).toContain("must not start yet");
|
|
66
|
-
expect(instruction).toContain("code-reviewer");
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("asks for the review when the implementation is done", () => {
|
|
70
|
-
const pending = transitionToReviewPending(createState("t"), ["a.ts", "b.ts"]);
|
|
71
|
-
const state = startReview(pending, [
|
|
72
|
-
{ id: "chunk-1", label: "packages/x (2 files)", files: ["a.ts", "b.ts"], status: "pending" },
|
|
73
|
-
]);
|
|
74
|
-
const view = buildPhaseView(state, []);
|
|
75
|
-
const instruction = buildPhaseInstruction(state, view);
|
|
76
|
-
expect(instruction).toContain("Phase 2");
|
|
77
|
-
expect(instruction).toContain("chunk-1");
|
|
78
|
-
expect(instruction).toContain("never the whole repository");
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("asks for the fixes when the review found something", () => {
|
|
82
|
-
const state = { ...createState("t"), phase: "review_fixes" as const };
|
|
83
|
-
const view = buildPhaseView(state, [
|
|
84
|
-
{ id: 1, subject: "[REVIEW-FIX] Fix the race", status: "pending" },
|
|
85
|
-
]);
|
|
86
|
-
const instruction = buildPhaseInstruction(state, view);
|
|
87
|
-
expect(instruction).toContain("review-fix todo(s) open");
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe("the queued review todo", () => {
|
|
92
|
-
it("is one item with the source and the scope", () => {
|
|
93
|
-
const state = transitionToReviewPending(recordSignal(createState("t"), signal), [
|
|
94
|
-
"packages/notification/index.ts",
|
|
95
|
-
]);
|
|
96
|
-
const subject = buildReviewTodoSubject(state);
|
|
97
|
-
const description = buildReviewTodoDescription(state);
|
|
98
|
-
expect(subject.startsWith(REVIEW_PREFIX)).toBe(true);
|
|
99
|
-
expect(subject).toContain("code-reviewer");
|
|
100
|
-
expect(description).toContain("Source: code-reviewer");
|
|
101
|
-
expect(description).toContain("packages/notification/index.ts");
|
|
102
|
-
});
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe("the review chunks", () => {
|
|
106
|
-
const chunk: ReviewChunk = {
|
|
107
|
-
id: "chunk-1",
|
|
108
|
-
label: "packages/notification (2 files)",
|
|
109
|
-
files: ["packages/notification/index.ts"],
|
|
110
|
-
status: "pending",
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
it("names the chunk in the subject of its todo", () => {
|
|
114
|
-
const subject = buildChunkTodoSubject(chunk);
|
|
115
|
-
expect(subject.startsWith(REVIEW_PREFIX)).toBe(true);
|
|
116
|
-
expect(subject).toContain("chunk-1");
|
|
117
|
-
expect(subject).toContain("packages/notification");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("belongs to the todo that names it", () => {
|
|
121
|
-
expect(isChunkTodo({ subject: subject(chunk), status: "pending" }, chunk)).toBe(true);
|
|
122
|
-
// "chunk-1" must not match "chunk-10".
|
|
123
|
-
expect(isChunkTodo({ subject: "[REVIEW] chunk-10: other", status: "pending" }, chunk)).toBe(
|
|
124
|
-
false,
|
|
125
|
-
);
|
|
126
|
-
// An implementation todo never belongs to a chunk.
|
|
127
|
-
expect(
|
|
128
|
-
isChunkTodo({ subject: "[IMPLEMENT] chunk-1: other", status: "pending" }, chunk),
|
|
129
|
-
).toBe(false);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("is done when its todo is completed", () => {
|
|
133
|
-
const state = startReview(createState("t"), [chunk]);
|
|
134
|
-
const synced = syncChunkStatus(state, [
|
|
135
|
-
{ subject: buildChunkTodoSubject(chunk), status: "completed" },
|
|
136
|
-
]);
|
|
137
|
-
expect(synced.chunks[0].status).toBe("done");
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it("keeps the progress when the todo list is empty", () => {
|
|
141
|
-
const state = startReview(createState("t"), [{ ...chunk, status: "done" }]);
|
|
142
|
-
const synced = syncChunkStatus(state, []);
|
|
143
|
-
expect(synced.chunks[0].status).toBe("done");
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
/** The subject of the todo of a chunk. */
|
|
148
|
-
function subject(chunk: ReviewChunk): string {
|
|
149
|
-
return buildChunkTodoSubject(chunk);
|
|
150
|
-
}
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The runtime of the two-phase workflow.
|
|
3
|
-
*
|
|
4
|
-
* The runtime is tested with a fake extension API: the handlers are called
|
|
5
|
-
* the way the session calls them, so the behavior (blocking, persistence,
|
|
6
|
-
* the phase transition, the steer and the prompt) is verified and not only
|
|
7
|
-
* the presence of a few source lines.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { describe, it, expect } from "bun:test";
|
|
11
|
-
import { execFileSync } from "node:child_process";
|
|
12
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
13
|
-
import { join } from "node:path";
|
|
14
|
-
import { initTwoPhaseReview } from "../src/runtime.js";
|
|
15
|
-
import type {
|
|
16
|
-
TodoReadResult,
|
|
17
|
-
TwoPhaseExtensionApi,
|
|
18
|
-
TwoPhaseRuntime,
|
|
19
|
-
} from "../src/runtime.js";
|
|
20
|
-
import { TwoPhaseStateStore } from "../src/state.js";
|
|
21
|
-
import { withTempDirAsync } from "./helpers.js";
|
|
22
|
-
|
|
23
|
-
type Handler = (...args: any[]) => unknown;
|
|
24
|
-
|
|
25
|
-
/** A fake extension API that records what the runtime does. */
|
|
26
|
-
class FakePi implements TwoPhaseExtensionApi {
|
|
27
|
-
handlers = new Map<string, Handler[]>();
|
|
28
|
-
entries: { type: string; data: unknown }[] = [];
|
|
29
|
-
messages: { content: string; options?: { deliverAs?: string } }[] = [];
|
|
30
|
-
status: { key: string; value: string }[] = [];
|
|
31
|
-
|
|
32
|
-
on(event: string, handler: Handler): void {
|
|
33
|
-
const list = this.handlers.get(event) ?? [];
|
|
34
|
-
list.push(handler);
|
|
35
|
-
this.handlers.set(event, list);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
appendEntry(type: string, data: unknown): void {
|
|
39
|
-
this.entries.push({ type, data });
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async sendUserMessage(
|
|
43
|
-
content: string,
|
|
44
|
-
options?: { deliverAs?: "steer" | "followUp" },
|
|
45
|
-
): Promise<void> {
|
|
46
|
-
this.messages.push({ content, options });
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** Call every handler of the event. */
|
|
50
|
-
async emit(event: string, ...args: unknown[]): Promise<unknown[]> {
|
|
51
|
-
const list = this.handlers.get(event) ?? [];
|
|
52
|
-
const results: unknown[] = [];
|
|
53
|
-
for (const handler of list) results.push(await handler(...args));
|
|
54
|
-
return results;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** A fake session context. */
|
|
59
|
-
function context(sessionId = "session-1") {
|
|
60
|
-
return {
|
|
61
|
-
sessionManager: { getSessionId: () => sessionId },
|
|
62
|
-
ui: {
|
|
63
|
-
setStatus: (key: string, value: string) => {
|
|
64
|
-
// The status line is a convenience; it is recorded, not asserted.
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/** A Git repository with one committed file. */
|
|
71
|
-
function makeRepo(root: string): void {
|
|
72
|
-
const git = (...args: string[]): void => {
|
|
73
|
-
execFileSync(
|
|
74
|
-
"git",
|
|
75
|
-
[
|
|
76
|
-
"-c",
|
|
77
|
-
"user.email=test@example.com",
|
|
78
|
-
"-c",
|
|
79
|
-
"user.name=Test",
|
|
80
|
-
"-c",
|
|
81
|
-
"commit.gpgsign=false",
|
|
82
|
-
"-c",
|
|
83
|
-
"core.hooksPath=/dev/null",
|
|
84
|
-
...args,
|
|
85
|
-
],
|
|
86
|
-
{ cwd: root, stdio: "ignore" },
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
git("init", "-q");
|
|
90
|
-
mkdirSync(join(root, "packages", "app"), { recursive: true });
|
|
91
|
-
writeFileSync(join(root, "packages", "app", "index.ts"), "export const a = 1;\n");
|
|
92
|
-
git("add", "-A");
|
|
93
|
-
git("commit", "-qm", "base");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** The todo list the runtime reads. */
|
|
97
|
-
function reader(items: TodoReadResult["todos"], available = true): (ctx: unknown) => Promise<TodoReadResult> {
|
|
98
|
-
return async () => ({
|
|
99
|
-
available,
|
|
100
|
-
todos: available ? items : [],
|
|
101
|
-
reason: available ? undefined : "the todo provider is not available",
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
describe("the two-phase runtime", () => {
|
|
106
|
-
it("blocks a comprehensive review while the implementation runs", async () => {
|
|
107
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
108
|
-
const pi = new FakePi();
|
|
109
|
-
const runtime = await initTwoPhaseReview({
|
|
110
|
-
pi,
|
|
111
|
-
readTodos: reader([
|
|
112
|
-
{ id: 1, subject: "[IMPLEMENT] Add the storage", status: "pending" },
|
|
113
|
-
]),
|
|
114
|
-
workspaceRoot: () => dir,
|
|
115
|
-
store: new TwoPhaseStateStore(dir),
|
|
116
|
-
});
|
|
117
|
-
await pi.emit("session_start", {}, context());
|
|
118
|
-
|
|
119
|
-
const result = (await pi.emit(
|
|
120
|
-
"tool_call",
|
|
121
|
-
{ toolName: "code-reviewer", input: { files: ["index.ts"] } },
|
|
122
|
-
context(),
|
|
123
|
-
))[0] as { block?: boolean; reason?: string };
|
|
124
|
-
|
|
125
|
-
expect(result.block).toBe(true);
|
|
126
|
-
expect(result.reason).toMatch(/Phase 1 \(implementation\) is still running/);
|
|
127
|
-
// The signal is queued, not lost.
|
|
128
|
-
expect(runtime.getState().signals.length).toBe(1);
|
|
129
|
-
expect(runtime.getState().phase).toBe("implementation");
|
|
130
|
-
// The queued review is part of the session.
|
|
131
|
-
expect(pi.entries.length).toBe(1);
|
|
132
|
-
expect(pi.entries[0].type).toBe("harness-two-phase-review");
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
it("does not block a task level check", async () => {
|
|
137
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
138
|
-
const pi = new FakePi();
|
|
139
|
-
await initTwoPhaseReview({
|
|
140
|
-
pi,
|
|
141
|
-
readTodos: reader([{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" }]),
|
|
142
|
-
workspaceRoot: () => dir,
|
|
143
|
-
store: new TwoPhaseStateStore(dir),
|
|
144
|
-
});
|
|
145
|
-
await pi.emit("session_start", {}, context());
|
|
146
|
-
|
|
147
|
-
const result = (await pi.emit(
|
|
148
|
-
"tool_call",
|
|
149
|
-
{ toolName: "lens_diagnostics", input: { paths: ["index.ts"] } },
|
|
150
|
-
context(),
|
|
151
|
-
))[0] as { block?: boolean };
|
|
152
|
-
|
|
153
|
-
expect(result).toEqual({});
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it("lets an explicit request of the human run the review", async () => {
|
|
158
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
159
|
-
const pi = new FakePi();
|
|
160
|
-
await initTwoPhaseReview({
|
|
161
|
-
pi,
|
|
162
|
-
readTodos: reader([{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" }]),
|
|
163
|
-
workspaceRoot: () => dir,
|
|
164
|
-
store: new TwoPhaseStateStore(dir),
|
|
165
|
-
});
|
|
166
|
-
await pi.emit("session_start", {}, context());
|
|
167
|
-
await pi.emit("message_end", {
|
|
168
|
-
message: { role: "user", content: "please review the diff now" },
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const result = (await pi.emit(
|
|
172
|
-
"tool_call",
|
|
173
|
-
{ toolName: "code-reviewer", input: { files: ["index.ts"] } },
|
|
174
|
-
context(),
|
|
175
|
-
))[0] as { block?: boolean };
|
|
176
|
-
|
|
177
|
-
expect(result).toEqual({});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("ignores a request that the harness sent itself", async () => {
|
|
182
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
183
|
-
const pi = new FakePi();
|
|
184
|
-
await initTwoPhaseReview({
|
|
185
|
-
pi,
|
|
186
|
-
readTodos: reader([{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" }]),
|
|
187
|
-
workspaceRoot: () => dir,
|
|
188
|
-
store: new TwoPhaseStateStore(dir),
|
|
189
|
-
});
|
|
190
|
-
await pi.emit("session_start", {}, context());
|
|
191
|
-
await pi.emit("message_end", {
|
|
192
|
-
message: { role: "user", content: "[harness:two-phase] please review the diff" },
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
const result = (await pi.emit(
|
|
196
|
-
"tool_call",
|
|
197
|
-
{ toolName: "code-reviewer", input: { files: ["index.ts"] } },
|
|
198
|
-
context(),
|
|
199
|
-
))[0] as { block?: boolean };
|
|
200
|
-
|
|
201
|
-
expect(result.block).toBe(true);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("blocks the review when the todo list cannot be read", async () => {
|
|
206
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
207
|
-
const pi = new FakePi();
|
|
208
|
-
const runtime = await initTwoPhaseReview({
|
|
209
|
-
pi,
|
|
210
|
-
readTodos: reader([], false),
|
|
211
|
-
workspaceRoot: () => dir,
|
|
212
|
-
store: new TwoPhaseStateStore(dir),
|
|
213
|
-
});
|
|
214
|
-
await pi.emit("session_start", {}, context());
|
|
215
|
-
|
|
216
|
-
const result = (await pi.emit(
|
|
217
|
-
"tool_call",
|
|
218
|
-
{ toolName: "code-reviewer", input: { files: ["index.ts"] } },
|
|
219
|
-
context(),
|
|
220
|
-
))[0] as { block?: boolean; reason?: string };
|
|
221
|
-
|
|
222
|
-
expect(result.block).toBe(true);
|
|
223
|
-
expect(result.reason).toMatch(/todo list of the session is not readable/);
|
|
224
|
-
// The phase did not move either.
|
|
225
|
-
expect(runtime.getState().phase).toBe("implementation");
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it("starts the review when the implementation is done", async () => {
|
|
230
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
231
|
-
makeRepo(dir);
|
|
232
|
-
writeFileSync(join(dir, "packages", "app", "index.ts"), "export const a = 2;\n");
|
|
233
|
-
|
|
234
|
-
const pi = new FakePi();
|
|
235
|
-
const runtime = await initTwoPhaseReview({
|
|
236
|
-
pi,
|
|
237
|
-
readTodos: reader([
|
|
238
|
-
{ id: 1, subject: "[IMPLEMENT] Work", status: "completed" },
|
|
239
|
-
{ id: 2, subject: "[REVIEW] Review the task diff", status: "pending" },
|
|
240
|
-
]),
|
|
241
|
-
workspaceRoot: () => dir,
|
|
242
|
-
store: new TwoPhaseStateStore(dir),
|
|
243
|
-
});
|
|
244
|
-
await pi.emit("session_start", {}, context());
|
|
245
|
-
await pi.emit("turn_end", {}, context());
|
|
246
|
-
|
|
247
|
-
expect(runtime.getState().phase).toBe("review");
|
|
248
|
-
expect(runtime.getState().scopeFiles.length).toBeGreaterThan(0);
|
|
249
|
-
// The review is started with a steer, not with a tool call.
|
|
250
|
-
expect(pi.messages.length).toBe(1);
|
|
251
|
-
expect(pi.messages[0].options?.deliverAs).toBe("steer");
|
|
252
|
-
expect(pi.messages[0].content).toMatch(/Phase 2 \(review\) starts now/);
|
|
253
|
-
});
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it("does not start the review while the implementation is open", async () => {
|
|
257
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
258
|
-
const pi = new FakePi();
|
|
259
|
-
const runtime = await initTwoPhaseReview({
|
|
260
|
-
pi,
|
|
261
|
-
readTodos: reader([
|
|
262
|
-
{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" },
|
|
263
|
-
{ id: 2, subject: "[REVIEW] Review the task diff", status: "pending" },
|
|
264
|
-
]),
|
|
265
|
-
workspaceRoot: () => dir,
|
|
266
|
-
store: new TwoPhaseStateStore(dir),
|
|
267
|
-
});
|
|
268
|
-
await pi.emit("session_start", {}, context());
|
|
269
|
-
await pi.emit("turn_end", {}, context());
|
|
270
|
-
|
|
271
|
-
expect(runtime.getState().phase).toBe("implementation");
|
|
272
|
-
expect(pi.messages.length).toBe(0);
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
it("puts the rules and the phase into the system prompt", async () => {
|
|
277
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
278
|
-
const pi = new FakePi();
|
|
279
|
-
await initTwoPhaseReview({
|
|
280
|
-
pi,
|
|
281
|
-
readTodos: reader([{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" }]),
|
|
282
|
-
workspaceRoot: () => dir,
|
|
283
|
-
store: new TwoPhaseStateStore(dir),
|
|
284
|
-
});
|
|
285
|
-
await pi.emit("session_start", {}, context());
|
|
286
|
-
|
|
287
|
-
const result = (await pi.emit(
|
|
288
|
-
"before_agent_start",
|
|
289
|
-
{ systemPrompt: "BASE PROMPT" },
|
|
290
|
-
context(),
|
|
291
|
-
))[0] as { systemPrompt?: string } | undefined;
|
|
292
|
-
|
|
293
|
-
expect(result?.systemPrompt).toMatch(/^BASE PROMPT/);
|
|
294
|
-
expect(result?.systemPrompt).toMatch(/Two-phase implementation and review/);
|
|
295
|
-
expect(result?.systemPrompt).toMatch(/Phase 1 \(implementation\)/);
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it("keeps the state when it cannot be written", async () => {
|
|
300
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
301
|
-
const pi = new FakePi();
|
|
302
|
-
const store = new TwoPhaseStateStore(dir);
|
|
303
|
-
const runtime = await initTwoPhaseReview({
|
|
304
|
-
pi,
|
|
305
|
-
readTodos: reader([{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" }]),
|
|
306
|
-
workspaceRoot: () => dir,
|
|
307
|
-
store: {
|
|
308
|
-
path: store.path.bind(store),
|
|
309
|
-
read: store.read.bind(store),
|
|
310
|
-
clear: store.clear.bind(store),
|
|
311
|
-
write: () => {
|
|
312
|
-
throw new Error("the disk is full");
|
|
313
|
-
},
|
|
314
|
-
} as unknown as TwoPhaseStateStore,
|
|
315
|
-
});
|
|
316
|
-
await pi.emit("session_start", {}, context());
|
|
317
|
-
|
|
318
|
-
const result = (await pi.emit(
|
|
319
|
-
"tool_call",
|
|
320
|
-
{ toolName: "code-reviewer", input: { files: ["index.ts"] } },
|
|
321
|
-
context(),
|
|
322
|
-
))[0] as { block?: boolean };
|
|
323
|
-
|
|
324
|
-
// The review is still deferred, but nothing was queued.
|
|
325
|
-
expect(result.block).toBe(true);
|
|
326
|
-
expect(runtime.getState().signals.length).toBe(0);
|
|
327
|
-
expect(pi.entries.length).toBe(0);
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
it("keeps the state of the session across a restart", async () => {
|
|
332
|
-
await withTempDirAsync("runtime", async (dir) => {
|
|
333
|
-
const store = new TwoPhaseStateStore(dir);
|
|
334
|
-
const first = new FakePi();
|
|
335
|
-
const runtime: TwoPhaseRuntime = await initTwoPhaseReview({
|
|
336
|
-
pi: first,
|
|
337
|
-
readTodos: reader([{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" }]),
|
|
338
|
-
workspaceRoot: () => dir,
|
|
339
|
-
store,
|
|
340
|
-
});
|
|
341
|
-
await first.emit("session_start", {}, context("session-7"));
|
|
342
|
-
await first.emit(
|
|
343
|
-
"tool_call",
|
|
344
|
-
{ toolName: "code-reviewer", input: { files: ["index.ts"] } },
|
|
345
|
-
context("session-7"),
|
|
346
|
-
);
|
|
347
|
-
expect(runtime.getState().signals.length).toBe(1);
|
|
348
|
-
|
|
349
|
-
const second = new FakePi();
|
|
350
|
-
const restarted = await initTwoPhaseReview({
|
|
351
|
-
pi: second,
|
|
352
|
-
readTodos: reader([{ id: 1, subject: "[IMPLEMENT] Work", status: "pending" }]),
|
|
353
|
-
workspaceRoot: () => dir,
|
|
354
|
-
store,
|
|
355
|
-
});
|
|
356
|
-
await second.emit("session_start", {}, context("session-7"));
|
|
357
|
-
|
|
358
|
-
expect(restarted.getState().signals.length).toBe(1);
|
|
359
|
-
expect(restarted.getState().startRevision).toBe(runtime.getState().startRevision);
|
|
360
|
-
});
|
|
361
|
-
});
|
|
362
|
-
});
|