@principles/pd-cli 1.152.11 → 1.152.13
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/dist/commands/candidate.d.ts +3 -3
- package/dist/commands/candidate.d.ts.map +1 -1
- package/dist/commands/candidate.js +9 -21
- package/dist/commands/candidate.js.map +1 -1
- package/dist/index.js +0 -0
- package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
- package/dist/services/rulehost-pipeline-runner.js +4 -17
- package/dist/services/rulehost-pipeline-runner.js.map +1 -1
- package/package.json +13 -7
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/intent-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/intent-flag-wiring.test.js +0 -237
- package/dist/commands/__tests__/intent-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts +0 -18
- package/dist/commands/__tests__/legacy-cleanup.test.d.ts.map +0 -1
- package/dist/commands/__tests__/legacy-cleanup.test.js +0 -467
- package/dist/commands/__tests__/legacy-cleanup.test.js.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.d.ts +0 -15
- package/dist/commands/__tests__/mvp-smoke.test.d.ts.map +0 -1
- package/dist/commands/__tests__/mvp-smoke.test.js +0 -262
- package/dist/commands/__tests__/mvp-smoke.test.js.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts +0 -2
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.d.ts.map +0 -1
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js +0 -60
- package/dist/commands/__tests__/pain-retry-maxTokens-flag.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts +0 -21
- package/dist/commands/__tests__/rulecode-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js +0 -186
- package/dist/commands/__tests__/rulecode-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.d.ts +0 -16
- package/dist/commands/__tests__/rulecode-handler.test.d.ts.map +0 -1
- package/dist/commands/__tests__/rulecode-handler.test.js +0 -285
- package/dist/commands/__tests__/rulecode-handler.test.js.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts +0 -24
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js +0 -232
- package/dist/commands/__tests__/run-rulehost-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts +0 -15
- package/dist/commands/__tests__/runtime-activation-nextaction.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js +0 -73
- package/dist/commands/__tests__/runtime-activation-nextaction.test.js.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts +0 -20
- package/dist/commands/__tests__/runtime-probe-config.test.d.ts.map +0 -1
- package/dist/commands/__tests__/runtime-probe-config.test.js +0 -389
- package/dist/commands/__tests__/runtime-probe-config.test.js.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts +0 -9
- package/dist/commands/__tests__/telemetry-flag-wiring.test.d.ts.map +0 -1
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js +0 -76
- package/dist/commands/__tests__/telemetry-flag-wiring.test.js.map +0 -1
- package/dist/commands/__tests__/version.test.d.ts +0 -2
- package/dist/commands/__tests__/version.test.d.ts.map +0 -1
- package/dist/commands/__tests__/version.test.js +0 -238
- package/dist/commands/__tests__/version.test.js.map +0 -1
- package/dist/commands/runtime-uat.guard.test.d.ts +0 -2
- package/dist/commands/runtime-uat.guard.test.d.ts.map +0 -1
- package/dist/commands/runtime-uat.guard.test.js +0 -153
- package/dist/commands/runtime-uat.guard.test.js.map +0 -1
- package/dist/services/__tests__/cli-output.test.d.ts +0 -18
- package/dist/services/__tests__/cli-output.test.d.ts.map +0 -1
- package/dist/services/__tests__/cli-output.test.js +0 -103
- package/dist/services/__tests__/cli-output.test.js.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts +0 -2
- package/dist/services/__tests__/evaluator-runner-deps.test.d.ts.map +0 -1
- package/dist/services/__tests__/evaluator-runner-deps.test.js +0 -343
- package/dist/services/__tests__/evaluator-runner-deps.test.js.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.d.ts +0 -2
- package/dist/services/__tests__/rulehost-readiness.test.d.ts.map +0 -1
- package/dist/services/__tests__/rulehost-readiness.test.js +0 -311
- package/dist/services/__tests__/rulehost-readiness.test.js.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts +0 -18
- package/dist/services/__tests__/runtime-adapter-resolver.test.d.ts.map +0 -1
- package/dist/services/__tests__/runtime-adapter-resolver.test.js +0 -673
- package/dist/services/__tests__/runtime-adapter-resolver.test.js.map +0 -1
- package/dist/utils/production-workspace-guard.test.d.ts +0 -2
- package/dist/utils/production-workspace-guard.test.d.ts.map +0 -1
- package/dist/utils/production-workspace-guard.test.js +0 -137
- package/dist/utils/production-workspace-guard.test.js.map +0 -1
- package/scripts/llm-dogfood.ts +0 -456
- package/scripts/migrate-illegal-expected-decision.ts +0 -252
- package/src/commands/__tests__/intent-flag-wiring.test.ts +0 -282
- package/src/commands/__tests__/legacy-cleanup.test.ts +0 -602
- package/src/commands/__tests__/mvp-smoke.test.ts +0 -300
- package/src/commands/__tests__/pain-retry-maxTokens-flag.test.ts +0 -73
- package/src/commands/__tests__/rulecode-flag-wiring.test.ts +0 -237
- package/src/commands/__tests__/rulecode-handler.test.ts +0 -369
- package/src/commands/__tests__/run-rulehost-flag-wiring.test.ts +0 -292
- package/src/commands/__tests__/runtime-activation-nextaction.test.ts +0 -81
- package/src/commands/__tests__/runtime-probe-config.test.ts +0 -432
- package/src/commands/__tests__/telemetry-flag-wiring.test.ts +0 -84
- package/src/commands/__tests__/version.test.ts +0 -251
- package/src/commands/admission-gate.ts +0 -30
- package/src/commands/artifact.ts +0 -82
- package/src/commands/build-trajectory-evidence.ts +0 -298
- package/src/commands/candidate.ts +0 -1260
- package/src/commands/codex-ingest-catchup.ts +0 -114
- package/src/commands/codex-ingest-quarantine.ts +0 -127
- package/src/commands/codex-reconcile.ts +0 -84
- package/src/commands/codex-setup.ts +0 -476
- package/src/commands/codex-worker.ts +0 -185
- package/src/commands/command-helpers.ts +0 -24
- package/src/commands/config-doctor.ts +0 -193
- package/src/commands/console.ts +0 -797
- package/src/commands/context.ts +0 -72
- package/src/commands/demo-story-a.ts +0 -241
- package/src/commands/diagnose.ts +0 -756
- package/src/commands/errors-list.ts +0 -441
- package/src/commands/evolution-tasks-list.ts +0 -48
- package/src/commands/evolution-tasks-show.ts +0 -62
- package/src/commands/flow.ts +0 -60
- package/src/commands/health-codex.ts +0 -576
- package/src/commands/health.ts +0 -315
- package/src/commands/history.ts +0 -63
- package/src/commands/intent.ts +0 -457
- package/src/commands/legacy-cleanup.ts +0 -531
- package/src/commands/legacy-import.ts +0 -104
- package/src/commands/mvp-smoke.ts +0 -160
- package/src/commands/pain-evidence.ts +0 -226
- package/src/commands/pain-list.ts +0 -239
- package/src/commands/pain-record.ts +0 -612
- package/src/commands/pain-retry.ts +0 -916
- package/src/commands/principles-stats.ts +0 -700
- package/src/commands/proven-channel-baseline.ts +0 -115
- package/src/commands/quality-scorecard.ts +0 -272
- package/src/commands/remediation-output.ts +0 -66
- package/src/commands/rulecode.ts +0 -465
- package/src/commands/run.ts +0 -89
- package/src/commands/runtime-activation.ts +0 -1629
- package/src/commands/runtime-artifact-repair.ts +0 -524
- package/src/commands/runtime-canary.ts +0 -395
- package/src/commands/runtime-compatibility-scan.ts +0 -105
- package/src/commands/runtime-diagnostics-export.ts +0 -229
- package/src/commands/runtime-features.ts +0 -153
- package/src/commands/runtime-gfi-snapshot.ts +0 -135
- package/src/commands/runtime-health-snapshot.ts +0 -108
- package/src/commands/runtime-init.ts +0 -429
- package/src/commands/runtime-internalization-enqueue-successors.ts +0 -530
- package/src/commands/runtime-internalization-integrity-repair.ts +0 -79
- package/src/commands/runtime-internalization-integrity.ts +0 -107
- package/src/commands/runtime-internalization-queue.ts +0 -135
- package/src/commands/runtime-internalization-retry.ts +0 -191
- package/src/commands/runtime-internalization-run-once.ts +0 -791
- package/src/commands/runtime-internalization-run-rulehost.ts +0 -749
- package/src/commands/runtime-internalization-wake-once.ts +0 -87
- package/src/commands/runtime-pain-flood-simulation.ts +0 -121
- package/src/commands/runtime-pruning.ts +0 -438
- package/src/commands/runtime-recovery-failed-tasks.ts +0 -258
- package/src/commands/runtime-recovery.ts +0 -109
- package/src/commands/runtime-synthetic-baseline.ts +0 -70
- package/src/commands/runtime-uat.guard.test.ts +0 -175
- package/src/commands/runtime-uat.ts +0 -380
- package/src/commands/runtime.ts +0 -473
- package/src/commands/samples-list.ts +0 -39
- package/src/commands/samples-review.ts +0 -36
- package/src/commands/task.ts +0 -271
- package/src/commands/telemetry.ts +0 -349
- package/src/commands/trace.ts +0 -174
- package/src/commands/trajectory-db-unavailable.ts +0 -19
- package/src/commands/trajectory.ts +0 -64
- package/src/commands/version.ts +0 -49
- package/src/config-reader.ts +0 -122
- package/src/index.ts +0 -1276
- package/src/legacy/legacy-import.ts +0 -179
- package/src/legacy/session-history-import.ts +0 -203
- package/src/resolve-workspace.ts +0 -106
- package/src/services/__tests__/cli-output.test.ts +0 -130
- package/src/services/__tests__/evaluator-runner-deps.test.ts +0 -382
- package/src/services/__tests__/rulehost-readiness.test.ts +0 -363
- package/src/services/__tests__/runtime-adapter-resolver.test.ts +0 -793
- package/src/services/cli-output.ts +0 -95
- package/src/services/config-doctor.ts +0 -697
- package/src/services/console-launcher.ts +0 -537
- package/src/services/demo-rule-compiler.ts +0 -40
- package/src/services/demo-story-a-runner.ts +0 -471
- package/src/services/mainline-snapshot-assembler.ts +0 -579
- package/src/services/pain-flood-simulation-runner.ts +0 -462
- package/src/services/pd-config-loader.ts +0 -433
- package/src/services/proven-channel-baseline-runner.ts +0 -157
- package/src/services/quality-scorecard/data-extractor.ts +0 -150
- package/src/services/quality-scorecard/local-evaluator.ts +0 -142
- package/src/services/quality-scorecard/strong-model-gate.ts +0 -202
- package/src/services/resolve-runtime-from-pd-config.ts +0 -230
- package/src/services/rulehost-pipeline-runner.ts +0 -1216
- package/src/services/rulehost-readiness.ts +0 -326
- package/src/services/runtime-adapter-resolver.ts +0 -364
- package/src/services/synthetic-baseline-runner.ts +0 -400
- package/src/services/version-report.ts +0 -253
- package/src/services/workspace-tool-semantics.ts +0 -26
- package/src/utils/path-security.ts +0 -96
- package/src/utils/production-workspace-guard.test.ts +0 -157
- package/src/utils/production-workspace-guard.ts +0 -210
- package/tests/bdd/cli-contract.steps.ts +0 -346
- package/tests/bdd/principles-stats.steps.ts +0 -211
- package/tests/bdd/support/gherkin-loader.ts +0 -147
- package/tests/bdd/support/repo-root.ts +0 -62
- package/tests/bdd/support/vitest-bdd.ts +0 -179
- package/tests/commands/admission-gate-coverage.test.ts +0 -79
- package/tests/commands/build-trajectory-evidence.test.ts +0 -508
- package/tests/commands/candidate-audit-repair.test.ts +0 -421
- package/tests/commands/candidate-intake.test.ts +0 -732
- package/tests/commands/candidate-internalization-backfill.test.ts +0 -548
- package/tests/commands/candidate-internalize-lineage.test.ts +0 -565
- package/tests/commands/candidate-internalize.test.ts +0 -299
- package/tests/commands/candidate-route.test.ts +0 -329
- package/tests/commands/candidate-show.test.ts +0 -95
- package/tests/commands/cli-command-tree.test.ts +0 -144
- package/tests/commands/cli-help-snapshot.test.ts +0 -155
- package/tests/commands/cli-skill-contract.test.ts +0 -121
- package/tests/commands/codex-consent-reversibility.steps.test.ts +0 -299
- package/tests/commands/codex-ingest-quarantine.test.ts +0 -136
- package/tests/commands/codex-setup.test.ts +0 -297
- package/tests/commands/codex-worker-daemon.test.ts +0 -95
- package/tests/commands/codex-worker-registration.test.ts +0 -207
- package/tests/commands/config-doctor.test.ts +0 -336
- package/tests/commands/console-launcher-edge-cases.test.ts +0 -388
- package/tests/commands/console-open.test.ts +0 -1381
- package/tests/commands/context.test.ts +0 -114
- package/tests/commands/demo-story-a.test.ts +0 -318
- package/tests/commands/diagnose.test.ts +0 -1803
- package/tests/commands/errors-list.test.ts +0 -679
- package/tests/commands/evolution-tasks-list.test.ts +0 -41
- package/tests/commands/evolution-tasks-show.test.ts +0 -46
- package/tests/commands/health-codex.test.ts +0 -349
- package/tests/commands/health-host-wiring.test.ts +0 -76
- package/tests/commands/health-reliability.test.ts +0 -99
- package/tests/commands/health.test.ts +0 -413
- package/tests/commands/intent.test.ts +0 -321
- package/tests/commands/legacy-cleanup.test.ts +0 -148
- package/tests/commands/pain-evidence.test.ts +0 -518
- package/tests/commands/pain-list.test.ts +0 -219
- package/tests/commands/pain-record-async.test.ts +0 -335
- package/tests/commands/pain-record-session-parser.test.ts +0 -228
- package/tests/commands/pain-record.test.ts +0 -851
- package/tests/commands/pain-retry.test.ts +0 -1121
- package/tests/commands/plugin-config-resolution-cutover.test.ts +0 -229
- package/tests/commands/pri-393-runtime-config-unification.test.ts +0 -443
- package/tests/commands/principles-stats-wiring.test.ts +0 -135
- package/tests/commands/principles-stats.test.ts +0 -274
- package/tests/commands/product-path-regression.test.ts +0 -86
- package/tests/commands/proven-channel-baseline.test.ts +0 -441
- package/tests/commands/rulecode.test.ts +0 -177
- package/tests/commands/run-rulehost-handler.test.ts +0 -908
- package/tests/commands/runtime-activation-approve-flag-wiring.test.ts +0 -227
- package/tests/commands/runtime-activation-deactivate-flag-wiring.test.ts +0 -167
- package/tests/commands/runtime-activation-dispatch-flag-wiring.test.ts +0 -262
- package/tests/commands/runtime-activation-governance-audit.test.ts +0 -95
- package/tests/commands/runtime-activation-list-flag-wiring.test.ts +0 -193
- package/tests/commands/runtime-activation-promote-flag-wiring.test.ts +0 -248
- package/tests/commands/runtime-activation-shadow-telemetry.test.ts +0 -130
- package/tests/commands/runtime-activation.test.ts +0 -2052
- package/tests/commands/runtime-artifact-repair-registration.test.ts +0 -74
- package/tests/commands/runtime-artifact-repair.test.ts +0 -404
- package/tests/commands/runtime-canary.test.ts +0 -430
- package/tests/commands/runtime-compatibility-scan.test.ts +0 -146
- package/tests/commands/runtime-diagnostics-export.test.ts +0 -175
- package/tests/commands/runtime-features.test.ts +0 -249
- package/tests/commands/runtime-health-snapshot.test.ts +0 -358
- package/tests/commands/runtime-init-empty-workspace.test.ts +0 -252
- package/tests/commands/runtime-init.test.ts +0 -420
- package/tests/commands/runtime-internalization-enqueue-successors.test.ts +0 -782
- package/tests/commands/runtime-internalization-integrity-repair.test.ts +0 -239
- package/tests/commands/runtime-internalization-integrity.test.ts +0 -140
- package/tests/commands/runtime-internalization-queue.test.ts +0 -380
- package/tests/commands/runtime-internalization-retry-owner-authority.test.ts +0 -431
- package/tests/commands/runtime-internalization-run-once-evaluator-parity.test.ts +0 -269
- package/tests/commands/runtime-internalization-run-once-language.test.ts +0 -303
- package/tests/commands/runtime-internalization-run-once-real-config.test.ts +0 -237
- package/tests/commands/runtime-internalization-run-once-rollout-parity.test.ts +0 -706
- package/tests/commands/runtime-internalization-run-once.test.ts +0 -1791
- package/tests/commands/runtime-internalization-wake-once.test.ts +0 -171
- package/tests/commands/runtime-internalization.test.ts +0 -53
- package/tests/commands/runtime-pain-flood-simulation.test.ts +0 -418
- package/tests/commands/runtime-pruning.test.ts +0 -694
- package/tests/commands/runtime-recovery-failed-tasks.test.ts +0 -328
- package/tests/commands/runtime-recovery.test.ts +0 -120
- package/tests/commands/runtime-synthetic-baseline.test.ts +0 -249
- package/tests/commands/runtime-uat.test.ts +0 -397
- package/tests/commands/runtime.test.ts +0 -392
- package/tests/commands/samples-list.test.ts +0 -43
- package/tests/commands/samples-review.test.ts +0 -41
- package/tests/commands/task.test.ts +0 -153
- package/tests/commands/telemetry.test.ts +0 -190
- package/tests/commands/trace.test.ts +0 -316
- package/tests/config-reader.test.ts +0 -143
- package/tests/e2e/candidate-intake-e2e.test.ts +0 -338
- package/tests/e2e/cli-full-flow.test.ts +0 -233
- package/tests/e2e/cross-package-acceptance.test.ts +0 -635
- package/tests/helpers/pd-cli-path.ts +0 -5
- package/tests/pd-cli-smoke.test.ts +0 -13
- package/tests/resolve-workspace.test.ts +0 -196
- package/tests/services/config-doctor-signal-health.test.ts +0 -109
- package/tests/services/console-launcher.test.ts +0 -114
- package/tests/services/demo-rule-compiler.test.ts +0 -242
- package/tests/services/mainline-snapshot-assembler.test.ts +0 -572
- package/tests/services/pd-config-loader.test.ts +0 -505
- package/tests/services/proven-channel-baseline-runner.test.ts +0 -30
- package/tests/services/quality-scorecard/strong-model-gate.test.ts +0 -133
- package/tests/services/resolve-runtime-from-pd-config.test.ts +0 -485
- package/tests/services/rulehost-pipeline-e2e.test.ts +0 -538
- package/tests/services/rulehost-pipeline-runner.test.ts +0 -1175
- package/tests/services/workspace-tool-semantics.test.ts +0 -76
- package/tests/utils/path-security.test.ts +0 -180
- package/tsconfig.json +0 -26
- package/vitest.config.ts +0 -9
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for acquireTrajectoryEvidenceFromDb — PRI-341 extraction behavior,
|
|
3
|
-
* PRI-642 typed classification (the legacy array wrapper was removed with
|
|
4
|
-
* its last production consumer).
|
|
5
|
-
*
|
|
6
|
-
* Uses real temporary SQLite DBs (trajectory.db) to validate evidence extraction.
|
|
7
|
-
*/
|
|
8
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
9
|
-
import Database from 'better-sqlite3';
|
|
10
|
-
import * as fs from 'fs';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import * as os from 'os';
|
|
13
|
-
import { MAX_EVIDENCE_ENTRIES } from '@principles/core/runtime-v2';
|
|
14
|
-
import { acquireTrajectoryEvidenceFromDb } from '../../src/commands/build-trajectory-evidence.js';
|
|
15
|
-
|
|
16
|
-
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
17
|
-
|
|
18
|
-
let tmpDir: string;
|
|
19
|
-
let stateDir: string;
|
|
20
|
-
|
|
21
|
-
function createStateDir(): string {
|
|
22
|
-
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'pd-trajectory-test-'));
|
|
23
|
-
stateDir = path.join(tmpDir, '.state');
|
|
24
|
-
fs.mkdirSync(stateDir, { recursive: true });
|
|
25
|
-
return stateDir;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function createTrajectoryDb(): Database.Database {
|
|
29
|
-
const dbPath = path.join(stateDir, 'trajectory.db');
|
|
30
|
-
const db = new Database(dbPath);
|
|
31
|
-
|
|
32
|
-
db.exec(`
|
|
33
|
-
CREATE TABLE IF NOT EXISTS sessions (
|
|
34
|
-
session_id TEXT PRIMARY KEY,
|
|
35
|
-
started_at TEXT,
|
|
36
|
-
updated_at TEXT
|
|
37
|
-
)
|
|
38
|
-
`);
|
|
39
|
-
|
|
40
|
-
db.exec(`
|
|
41
|
-
CREATE TABLE IF NOT EXISTS assistant_turns (
|
|
42
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
43
|
-
session_id TEXT NOT NULL,
|
|
44
|
-
run_id TEXT,
|
|
45
|
-
provider TEXT,
|
|
46
|
-
model TEXT,
|
|
47
|
-
raw_text TEXT,
|
|
48
|
-
sanitized_text TEXT,
|
|
49
|
-
blob_ref TEXT,
|
|
50
|
-
stop_reason TEXT,
|
|
51
|
-
thinking_blocks_count INTEGER,
|
|
52
|
-
created_at TEXT NOT NULL
|
|
53
|
-
)
|
|
54
|
-
`);
|
|
55
|
-
|
|
56
|
-
db.exec(`
|
|
57
|
-
CREATE TABLE IF NOT EXISTS user_turns (
|
|
58
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
59
|
-
session_id TEXT NOT NULL,
|
|
60
|
-
turn_index INTEGER NOT NULL DEFAULT 0,
|
|
61
|
-
raw_excerpt TEXT,
|
|
62
|
-
correction_detected INTEGER NOT NULL DEFAULT 0,
|
|
63
|
-
correction_cue TEXT,
|
|
64
|
-
created_at TEXT NOT NULL
|
|
65
|
-
)
|
|
66
|
-
`);
|
|
67
|
-
|
|
68
|
-
db.exec(`
|
|
69
|
-
CREATE TABLE IF NOT EXISTS tool_calls (
|
|
70
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
71
|
-
session_id TEXT NOT NULL,
|
|
72
|
-
tool_name TEXT NOT NULL,
|
|
73
|
-
outcome TEXT NOT NULL,
|
|
74
|
-
duration_ms INTEGER,
|
|
75
|
-
exit_code INTEGER,
|
|
76
|
-
error_type TEXT,
|
|
77
|
-
error_message TEXT,
|
|
78
|
-
gfi_before REAL,
|
|
79
|
-
gfi_after REAL,
|
|
80
|
-
params_json TEXT NOT NULL DEFAULT '{}',
|
|
81
|
-
result_preview TEXT,
|
|
82
|
-
created_at TEXT NOT NULL
|
|
83
|
-
)
|
|
84
|
-
`);
|
|
85
|
-
|
|
86
|
-
return db;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function insertAssistantTurn(
|
|
90
|
-
db: Database.Database,
|
|
91
|
-
sessionId: string,
|
|
92
|
-
sanitizedText: string,
|
|
93
|
-
createdAt: string,
|
|
94
|
-
): void {
|
|
95
|
-
db.prepare(`
|
|
96
|
-
INSERT INTO assistant_turns (session_id, sanitized_text, created_at)
|
|
97
|
-
VALUES (?, ?, ?)
|
|
98
|
-
`).run(sessionId, sanitizedText, createdAt);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function insertUserTurn(
|
|
102
|
-
db: Database.Database,
|
|
103
|
-
sessionId: string,
|
|
104
|
-
rawExcerpt: string,
|
|
105
|
-
correctionDetected: boolean,
|
|
106
|
-
createdAt: string,
|
|
107
|
-
): void {
|
|
108
|
-
db.prepare(`
|
|
109
|
-
INSERT INTO user_turns (session_id, turn_index, raw_excerpt, correction_detected, created_at)
|
|
110
|
-
VALUES (?, ?, ?, ?, ?)
|
|
111
|
-
`).run(sessionId, 0, rawExcerpt, correctionDetected ? 1 : 0, createdAt);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function insertToolCall(
|
|
115
|
-
db: Database.Database,
|
|
116
|
-
sessionId: string,
|
|
117
|
-
toolName: string,
|
|
118
|
-
outcome: string,
|
|
119
|
-
errorType: string | null,
|
|
120
|
-
exitCode: number | null,
|
|
121
|
-
createdAt: string,
|
|
122
|
-
resultPreview?: string | null,
|
|
123
|
-
): void {
|
|
124
|
-
db.prepare(`
|
|
125
|
-
INSERT INTO tool_calls (session_id, tool_name, outcome, error_type, exit_code, duration_ms, params_json, result_preview, created_at)
|
|
126
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
127
|
-
`).run(sessionId, toolName, outcome, errorType, exitCode, 100, '{}', resultPreview ?? null, createdAt);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// ── Tests ───────────────────────────────────────────────────────────────────
|
|
131
|
-
|
|
132
|
-
describe('acquireTrajectoryEvidenceFromDb — behavior via typed API (PRI-341 extraction, PRI-642 wrapper removal)', () => {
|
|
133
|
-
beforeEach(() => {
|
|
134
|
-
createStateDir();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
afterEach(() => {
|
|
138
|
-
try {
|
|
139
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
140
|
-
} catch {
|
|
141
|
-
// ignore cleanup errors
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
/** Available-class entries, or the unavailable reason for assertions. */
|
|
146
|
-
function acquire(sessionId: string | undefined) {
|
|
147
|
-
return acquireTrajectoryEvidenceFromDb(stateDir, sessionId, tmpDir);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function entriesOf(sessionId: string) {
|
|
151
|
-
const result = acquire(sessionId);
|
|
152
|
-
expect(result.status).toBe('available');
|
|
153
|
-
return result.status === 'available' ? result.entries : [];
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function insertSession(db: Database.Database, sessionId: string): void {
|
|
157
|
-
db.prepare('INSERT INTO sessions (session_id, started_at, updated_at) VALUES (?, ?, ?)')
|
|
158
|
-
.run(sessionId, '2026-01-01T09:00:00Z', '2026-01-01T09:00:00Z');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
it('returns available entries (≤ MAX_EVIDENCE_ENTRIES) from assistant turns', () => {
|
|
162
|
-
const db = createTrajectoryDb();
|
|
163
|
-
insertSession(db, '123');
|
|
164
|
-
insertAssistantTurn(db, '123', 'First assistant response about backups', '2026-01-01T10:00:00Z');
|
|
165
|
-
insertAssistantTurn(db, '123', 'Second response about validation', '2026-01-01T10:01:00Z');
|
|
166
|
-
insertAssistantTurn(db, '123', 'Third response about error handling', '2026-01-01T10:02:00Z');
|
|
167
|
-
db.close();
|
|
168
|
-
|
|
169
|
-
const entries = entriesOf('123');
|
|
170
|
-
|
|
171
|
-
expect(entries.length).toBeGreaterThan(0);
|
|
172
|
-
expect(entries.length).toBeLessThanOrEqual(MAX_EVIDENCE_ENTRIES);
|
|
173
|
-
for (const entry of entries) {
|
|
174
|
-
expect(entry.sourceRef).toBeTruthy();
|
|
175
|
-
expect(entry.note).toBeTruthy();
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
it('classifies an undefined session as session_not_found (no placeholder entries)', () => {
|
|
180
|
-
const db = createTrajectoryDb();
|
|
181
|
-
db.close();
|
|
182
|
-
const result = acquire(undefined);
|
|
183
|
-
expect(result.status).toBe('unavailable');
|
|
184
|
-
if (result.status !== 'unavailable') return;
|
|
185
|
-
expect(result.reasonCode).toBe('session_not_found');
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('surfaces user correction turns with correctionDetected=true', () => {
|
|
189
|
-
const db = createTrajectoryDb();
|
|
190
|
-
insertSession(db, '123');
|
|
191
|
-
insertUserTurn(db, '123', 'Please fix the backup logic', true, '2026-01-01T09:59:00Z');
|
|
192
|
-
insertAssistantTurn(db, '123', 'I will fix the backup logic', '2026-01-01T10:00:00Z');
|
|
193
|
-
db.close();
|
|
194
|
-
|
|
195
|
-
const entries = entriesOf('123');
|
|
196
|
-
|
|
197
|
-
const ownerEntry = entries.find(e => e.sourceRef.startsWith('owner_message:'));
|
|
198
|
-
expect(ownerEntry).toBeDefined();
|
|
199
|
-
expect(ownerEntry!.note).toContain('fix the backup logic');
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
it('extracts failed tool_calls as evidence entries (PRI-358)', () => {
|
|
203
|
-
const db = createTrajectoryDb();
|
|
204
|
-
insertSession(db, '123');
|
|
205
|
-
insertToolCall(db, '123', 'bash', 'failure', 'non_zero_exit', 1, '2026-01-01T10:00:00Z');
|
|
206
|
-
insertToolCall(db, '123', 'write_file', 'success', null, 0, '2026-01-01T10:01:00Z');
|
|
207
|
-
insertToolCall(db, '123', 'bash', 'failure', 'timeout', 124, '2026-01-01T10:02:00Z');
|
|
208
|
-
db.close();
|
|
209
|
-
|
|
210
|
-
const entries = entriesOf('123');
|
|
211
|
-
|
|
212
|
-
const failureEntries = entries.filter(e => e.sourceRef.startsWith('tool_call_failure:'));
|
|
213
|
-
expect(failureEntries.length).toBe(2);
|
|
214
|
-
expect(failureEntries[0].note).toContain('bash');
|
|
215
|
-
expect(failureEntries[0].note).toContain('non_zero_exit');
|
|
216
|
-
expect(failureEntries[1].note).toContain('timeout');
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('limits failed tool_calls to 3 entries', () => {
|
|
220
|
-
const db = createTrajectoryDb();
|
|
221
|
-
insertSession(db, '123');
|
|
222
|
-
insertToolCall(db, '123', 'bash', 'failure', 'err1', 1, '2026-01-01T10:00:00Z');
|
|
223
|
-
insertToolCall(db, '123', 'bash', 'failure', 'err2', 2, '2026-01-01T10:01:00Z');
|
|
224
|
-
insertToolCall(db, '123', 'bash', 'failure', 'err3', 3, '2026-01-01T10:02:00Z');
|
|
225
|
-
insertToolCall(db, '123', 'bash', 'failure', 'err4', 4, '2026-01-01T10:03:00Z');
|
|
226
|
-
db.close();
|
|
227
|
-
|
|
228
|
-
const entries = entriesOf('123');
|
|
229
|
-
|
|
230
|
-
const failureEntries = entries.filter(e => e.sourceRef.startsWith('tool_call_failure:'));
|
|
231
|
-
expect(failureEntries.length).toBe(3);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it('handles a missing tool_calls table gracefully (classified unavailable, no throw)', () => {
|
|
235
|
-
const dbPath = path.join(stateDir, 'trajectory.db');
|
|
236
|
-
const db = new Database(dbPath);
|
|
237
|
-
db.exec("CREATE TABLE IF NOT EXISTS sessions (session_id TEXT PRIMARY KEY, started_at TEXT, updated_at TEXT)");
|
|
238
|
-
db.exec("CREATE TABLE IF NOT EXISTS assistant_turns (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL, sanitized_text TEXT, created_at TEXT NOT NULL)");
|
|
239
|
-
db.exec("CREATE TABLE IF NOT EXISTS user_turns (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL, turn_index INTEGER NOT NULL DEFAULT 0, raw_excerpt TEXT, correction_detected INTEGER NOT NULL DEFAULT 0, created_at TEXT NOT NULL)");
|
|
240
|
-
db.prepare('INSERT INTO sessions (session_id, started_at, updated_at) VALUES (?, ?, ?)').run('123', '2026-01-01T09:00:00Z', '2026-01-01T09:00:00Z');
|
|
241
|
-
db.close();
|
|
242
|
-
|
|
243
|
-
const result = acquire('123');
|
|
244
|
-
expect(result.status).toBe('unavailable');
|
|
245
|
-
if (result.status !== 'unavailable') return;
|
|
246
|
-
expect(['empty_trajectory', 'evidence_read_failed']).toContain(result.reasonCode);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('includes resultPreview in tool failure evidence note', () => {
|
|
250
|
-
const db = createTrajectoryDb();
|
|
251
|
-
insertSession(db, '123');
|
|
252
|
-
insertToolCall(db, '123', 'bash', 'failure', 'ENOENT', 1, '2026-01-01T10:00:00Z', 'Error: no such file or directory');
|
|
253
|
-
db.close();
|
|
254
|
-
|
|
255
|
-
const entries = entriesOf('123');
|
|
256
|
-
|
|
257
|
-
const failureEntry = entries.find(e => e.sourceRef.startsWith('tool_call_failure:'));
|
|
258
|
-
expect(failureEntry).toBeDefined();
|
|
259
|
-
expect(failureEntry!.note).toContain('ENOENT');
|
|
260
|
-
expect(failureEntry!.note).toContain('Error: no such file or directory');
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('includes truncation warning when stop_reason is length', () => {
|
|
264
|
-
const db = createTrajectoryDb();
|
|
265
|
-
insertSession(db, '123');
|
|
266
|
-
db.prepare("INSERT INTO assistant_turns (session_id, sanitized_text, stop_reason, created_at) VALUES (?, ?, ?, ?)")
|
|
267
|
-
.run('123', 'Partial output truncated...', 'length', '2026-01-01T10:00:00Z');
|
|
268
|
-
db.close();
|
|
269
|
-
|
|
270
|
-
const entries = entriesOf('123');
|
|
271
|
-
|
|
272
|
-
const agentEntry = entries.find(e => e.sourceRef.startsWith('agent_turn:'));
|
|
273
|
-
expect(agentEntry).toBeDefined();
|
|
274
|
-
expect(agentEntry!.note).toContain('Partial output truncated...');
|
|
275
|
-
expect(agentEntry!.note).toContain('[TRUNCATED: output cut off by length limit]');
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('does not include truncation warning when stop_reason is end_turn', () => {
|
|
279
|
-
const db = createTrajectoryDb();
|
|
280
|
-
insertSession(db, '123');
|
|
281
|
-
db.prepare("INSERT INTO assistant_turns (session_id, sanitized_text, stop_reason, created_at) VALUES (?, ?, ?, ?)")
|
|
282
|
-
.run('123', 'Complete output', 'end_turn', '2026-01-01T10:00:00Z');
|
|
283
|
-
db.close();
|
|
284
|
-
|
|
285
|
-
const entries = entriesOf('123');
|
|
286
|
-
|
|
287
|
-
const agentEntry = entries.find(e => e.sourceRef.startsWith('agent_turn:'));
|
|
288
|
-
expect(agentEntry).toBeDefined();
|
|
289
|
-
expect(agentEntry!.note).toBe('Complete output');
|
|
290
|
-
expect(agentEntry!.note).not.toContain('[TRUNCATED');
|
|
291
|
-
});
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
// ── PRI-642 Scope A — typed acquisition from trajectory.db (SPEC §7.3) ───────
|
|
295
|
-
|
|
296
|
-
describe('acquireTrajectoryEvidenceFromDb — typed CLI acquisition (PRI-642 Scope A)', () => {
|
|
297
|
-
beforeEach(() => {
|
|
298
|
-
createStateDir();
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
afterEach(() => {
|
|
302
|
-
try {
|
|
303
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
304
|
-
} catch {
|
|
305
|
-
// ignore cleanup errors
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('returns available with entries for a session that has turns', async () => {
|
|
310
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
311
|
-
const db = createTrajectoryDb();
|
|
312
|
-
// Turn writers upsert the sessions row — mirror the real DB shape.
|
|
313
|
-
db.prepare('INSERT INTO sessions (session_id, started_at, updated_at) VALUES (?, ?, ?)')
|
|
314
|
-
.run('real-session', '2026-01-01T09:00:00Z', '2026-01-01T09:00:00Z');
|
|
315
|
-
insertUserTurn(db, 'real-session', 'Owner correction', true, '2026-01-01T09:59:00Z');
|
|
316
|
-
insertAssistantTurn(db, 'real-session', 'assistant text', '2026-01-01T10:00:00Z');
|
|
317
|
-
db.close();
|
|
318
|
-
|
|
319
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'real-session', tmpDir);
|
|
320
|
-
|
|
321
|
-
expect(result.status).toBe('available');
|
|
322
|
-
if (result.status !== 'available') return;
|
|
323
|
-
expect(result.entries.length).toBeGreaterThan(0);
|
|
324
|
-
expect(result.entries.some(e => e.sourceRef.startsWith('owner_message:'))).toBe(true);
|
|
325
|
-
expect(result.entries.some(e => e.sourceRef.startsWith('agent_turn:'))).toBe(true);
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
it('returns unavailable/session_not_found for a session absent from the sessions table (SPEC 12.1.4)', async () => {
|
|
329
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
330
|
-
const db = createTrajectoryDb();
|
|
331
|
-
insertAssistantTurn(db, 'other-session', 'unrelated', '2026-01-01T10:00:00Z');
|
|
332
|
-
db.close();
|
|
333
|
-
|
|
334
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'no-such-session', tmpDir);
|
|
335
|
-
|
|
336
|
-
expect(result.status).toBe('unavailable');
|
|
337
|
-
if (result.status !== 'unavailable') return;
|
|
338
|
-
expect(result.reasonCode).toBe('session_not_found');
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
it('returns unavailable/session_not_found for the "cli" and "unknown" sentinels', async () => {
|
|
342
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
343
|
-
const db = createTrajectoryDb();
|
|
344
|
-
db.close();
|
|
345
|
-
|
|
346
|
-
const cliResult = acquireTrajectoryEvidenceFromDb(stateDir, 'cli', tmpDir);
|
|
347
|
-
const unknownResult = acquireTrajectoryEvidenceFromDb(stateDir, 'unknown', tmpDir);
|
|
348
|
-
|
|
349
|
-
expect(cliResult.status).toBe('unavailable');
|
|
350
|
-
expect(unknownResult.status).toBe('unavailable');
|
|
351
|
-
if (cliResult.status !== 'unavailable' || unknownResult.status !== 'unavailable') return;
|
|
352
|
-
expect(cliResult.reasonCode).toBe('session_not_found');
|
|
353
|
-
expect(unknownResult.reasonCode).toBe('session_not_found');
|
|
354
|
-
});
|
|
355
|
-
|
|
356
|
-
it('returns unavailable/trajectory_unavailable when trajectory.db is missing', async () => {
|
|
357
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
358
|
-
|
|
359
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'some-session', tmpDir);
|
|
360
|
-
|
|
361
|
-
expect(result.status).toBe('unavailable');
|
|
362
|
-
if (result.status !== 'unavailable') return;
|
|
363
|
-
expect(result.reasonCode).toBe('trajectory_unavailable');
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it('returns unavailable/empty_trajectory when the session exists but has no turns or tool calls', async () => {
|
|
367
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
368
|
-
const db = createTrajectoryDb();
|
|
369
|
-
db.prepare(`
|
|
370
|
-
INSERT INTO sessions (session_id, started_at, updated_at)
|
|
371
|
-
VALUES (?, ?, ?)
|
|
372
|
-
`).run('quiet-session', '2026-01-01T09:00:00Z', '2026-01-01T09:00:00Z');
|
|
373
|
-
db.close();
|
|
374
|
-
|
|
375
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'quiet-session', tmpDir);
|
|
376
|
-
|
|
377
|
-
expect(result.status).toBe('unavailable');
|
|
378
|
-
if (result.status !== 'unavailable') return;
|
|
379
|
-
expect(result.reasonCode).toBe('empty_trajectory');
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
it('returns a different reasonCode for unreadable DB vs empty trajectory (exec-prompt item 5)', async () => {
|
|
383
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
384
|
-
const db = createTrajectoryDb();
|
|
385
|
-
db.close();
|
|
386
|
-
// Corrupt the DB file after close so the read-only open fails.
|
|
387
|
-
const dbPath = path.join(stateDir, 'trajectory.db');
|
|
388
|
-
fs.writeFileSync(dbPath, Buffer.from('this is not a sqlite database at all'));
|
|
389
|
-
|
|
390
|
-
const unreadable = acquireTrajectoryEvidenceFromDb(stateDir, 'some-session', tmpDir);
|
|
391
|
-
|
|
392
|
-
const stateDir2 = createStateDir();
|
|
393
|
-
const db2 = createTrajectoryDb();
|
|
394
|
-
db2.close();
|
|
395
|
-
|
|
396
|
-
expect(unreadable.status).toBe('unavailable');
|
|
397
|
-
if (unreadable.status !== 'unavailable') return;
|
|
398
|
-
// Unreadable DB must not share a reasonCode with a real-but-empty session.
|
|
399
|
-
expect(unreadable.reasonCode).not.toBe('empty_trajectory');
|
|
400
|
-
expect(unreadable.reasonCode).toBe('evidence_read_failed');
|
|
401
|
-
});
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
// ── PRI-783 review P1: the binding fact gates degrade vs refuse ─────────────
|
|
405
|
-
// 'verified' = the sessions table was queried and DID contain the id;
|
|
406
|
-
// 'unverified' = DB missing / unopenable / id absent / sessions table
|
|
407
|
-
// unreadable. Only verified bindings may degrade to a bound submission.
|
|
408
|
-
|
|
409
|
-
describe('acquisition binding fact (PRI-783 review P1)', () => {
|
|
410
|
-
beforeEach(() => {
|
|
411
|
-
createStateDir();
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
afterEach(() => {
|
|
415
|
-
try {
|
|
416
|
-
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
417
|
-
} catch {
|
|
418
|
-
// ignore cleanup errors
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
it('session present with zero evidence → empty_trajectory, binding verified (degrade precondition)', async () => {
|
|
423
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
424
|
-
const db = createTrajectoryDb();
|
|
425
|
-
db.prepare('INSERT INTO sessions (session_id, started_at, updated_at) VALUES (?, ?, ?)')
|
|
426
|
-
.run('quiet-session', '2026-01-01T09:00:00Z', '2026-01-01T09:00:00Z');
|
|
427
|
-
insertUserTurn(db, 'quiet-session', 'ordinary message', false, '2026-01-01T09:01:00Z');
|
|
428
|
-
db.close();
|
|
429
|
-
|
|
430
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'quiet-session', tmpDir);
|
|
431
|
-
|
|
432
|
-
expect(result.status).toBe('unavailable');
|
|
433
|
-
if (result.status !== 'unavailable') return;
|
|
434
|
-
expect(result.reasonCode).toBe('empty_trajectory');
|
|
435
|
-
expect(result.binding).toBe('verified');
|
|
436
|
-
});
|
|
437
|
-
|
|
438
|
-
it('id absent from sessions table → session_not_found, binding unverified', async () => {
|
|
439
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
440
|
-
const db = createTrajectoryDb();
|
|
441
|
-
db.close();
|
|
442
|
-
|
|
443
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'no-such-session', tmpDir);
|
|
444
|
-
|
|
445
|
-
expect(result.status).toBe('unavailable');
|
|
446
|
-
if (result.status !== 'unavailable') return;
|
|
447
|
-
expect(result.reasonCode).toBe('session_not_found');
|
|
448
|
-
expect(result.binding).toBe('unverified');
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
it('missing trajectory.db → trajectory_unavailable, binding unverified', async () => {
|
|
452
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
453
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'some-session', tmpDir);
|
|
454
|
-
|
|
455
|
-
expect(result.status).toBe('unavailable');
|
|
456
|
-
if (result.status !== 'unavailable') return;
|
|
457
|
-
expect(result.reasonCode).toBe('trajectory_unavailable');
|
|
458
|
-
expect(result.binding).toBe('unverified');
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
it('corrupt DB (open fails) → evidence_read_failed, binding unverified', async () => {
|
|
462
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
463
|
-
const dbPath = path.join(stateDir, 'trajectory.db');
|
|
464
|
-
fs.writeFileSync(dbPath, Buffer.from('this is not a sqlite database at all'));
|
|
465
|
-
|
|
466
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'some-session', tmpDir);
|
|
467
|
-
|
|
468
|
-
expect(result.status).toBe('unavailable');
|
|
469
|
-
if (result.status !== 'unavailable') return;
|
|
470
|
-
expect(result.reasonCode).toBe('evidence_read_failed');
|
|
471
|
-
expect(result.binding).toBe('unverified');
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
it('session verified but evidence tables unreadable → evidence_read_failed, binding verified', async () => {
|
|
475
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
476
|
-
const db = createTrajectoryDb();
|
|
477
|
-
db.prepare('INSERT INTO sessions (session_id, started_at, updated_at) VALUES (?, ?, ?)')
|
|
478
|
-
.run('readable-session', '2026-01-01T09:00:00Z', '2026-01-01T09:00:00Z');
|
|
479
|
-
db.close();
|
|
480
|
-
// Drop the evidence tables after the session row exists: the sessions
|
|
481
|
-
// check passed, the evidence read cannot.
|
|
482
|
-
const raw = new Database(path.join(stateDir, 'trajectory.db'));
|
|
483
|
-
raw.exec('DROP TABLE user_turns');
|
|
484
|
-
raw.close();
|
|
485
|
-
|
|
486
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'readable-session', tmpDir);
|
|
487
|
-
|
|
488
|
-
expect(result.status).toBe('unavailable');
|
|
489
|
-
if (result.status !== 'unavailable') return;
|
|
490
|
-
expect(result.reasonCode).toBe('evidence_read_failed');
|
|
491
|
-
expect(result.binding).toBe('verified');
|
|
492
|
-
});
|
|
493
|
-
|
|
494
|
-
it('sessions table missing entirely → nothing is verified (unverified even when the reason is evidence_read_failed)', async () => {
|
|
495
|
-
const { acquireTrajectoryEvidenceFromDb } = await import('../../src/commands/build-trajectory-evidence.js');
|
|
496
|
-
const db = new Database(path.join(stateDir, 'trajectory.db'));
|
|
497
|
-
db.exec('CREATE TABLE user_turns (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL, raw_excerpt TEXT, correction_detected INTEGER NOT NULL DEFAULT 0, correction_cue TEXT, created_at TEXT NOT NULL)');
|
|
498
|
-
db.close();
|
|
499
|
-
|
|
500
|
-
const result = acquireTrajectoryEvidenceFromDb(stateDir, 'never-seen', tmpDir);
|
|
501
|
-
|
|
502
|
-
expect(result.status).toBe('unavailable');
|
|
503
|
-
if (result.status !== 'unavailable') return;
|
|
504
|
-
// assistant_turns/tool_calls tables missing → readFailed → evidence_read_failed
|
|
505
|
-
expect(result.reasonCode).toBe('evidence_read_failed');
|
|
506
|
-
expect(result.binding).toBe('unverified');
|
|
507
|
-
});
|
|
508
|
-
});
|