@principles/pd-cli 1.152.12 → 1.152.14
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.map +1 -1
- package/dist/commands/candidate.js +34 -7
- package/dist/commands/candidate.js.map +1 -1
- package/dist/commands/diagnose.d.ts.map +1 -1
- package/dist/commands/diagnose.js +23 -7
- package/dist/commands/diagnose.js.map +1 -1
- package/dist/commands/pain-retry.d.ts.map +1 -1
- package/dist/commands/pain-retry.js +21 -7
- package/dist/commands/pain-retry.js.map +1 -1
- package/package.json +13 -7
- package/CHANGELOG.md +0 -23
- 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 -1250
- 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 -1214
- 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 -628
- 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 -1242
- 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 -10
|
@@ -1,732 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { handleCandidateIntake } from '../../src/commands/candidate.js';
|
|
3
|
-
|
|
4
|
-
// Use vi.hoisted to define mocks that can be referenced in vi.mock factory
|
|
5
|
-
const { mockStateManager, mockAdapter, mockService, MockRuntimeStateManager, MockCandidateIntakeService, MockPrincipleTreeLedgerAdapter, MockCandidateIntakeError } = vi.hoisted(() => {
|
|
6
|
-
const mockStateManager = {
|
|
7
|
-
initialize: vi.fn().mockResolvedValue(undefined),
|
|
8
|
-
getCandidate: vi.fn(),
|
|
9
|
-
getArtifact: vi.fn(),
|
|
10
|
-
close: vi.fn().mockResolvedValue(undefined),
|
|
11
|
-
connection: {
|
|
12
|
-
getDb: () => ({
|
|
13
|
-
prepare: () => ({
|
|
14
|
-
run: vi.fn().mockReturnValue({ changes: 1 }),
|
|
15
|
-
}),
|
|
16
|
-
}),
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const mockAdapter = {
|
|
21
|
-
writeProbationEntry: vi.fn(),
|
|
22
|
-
existsForCandidate: vi.fn().mockReturnValue(null),
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const mockService = {
|
|
26
|
-
intake: vi.fn(),
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
// Mock error class
|
|
30
|
-
class MockCandidateIntakeError extends Error {
|
|
31
|
-
code: string;
|
|
32
|
-
context?: Record<string, unknown>;
|
|
33
|
-
constructor(message: string, code: string, context?: Record<string, unknown>) {
|
|
34
|
-
super(message);
|
|
35
|
-
this.name = 'CandidateIntakeError';
|
|
36
|
-
this.code = code;
|
|
37
|
-
this.context = context;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Create mock constructors
|
|
42
|
-
function MockRuntimeStateManager(this: any) {
|
|
43
|
-
return mockStateManager;
|
|
44
|
-
}
|
|
45
|
-
MockRuntimeStateManager.prototype = {};
|
|
46
|
-
|
|
47
|
-
function MockCandidateIntakeService(this: any) {
|
|
48
|
-
return mockService;
|
|
49
|
-
}
|
|
50
|
-
MockCandidateIntakeService.prototype = {};
|
|
51
|
-
|
|
52
|
-
function MockPrincipleTreeLedgerAdapter(this: any) {
|
|
53
|
-
return mockAdapter;
|
|
54
|
-
}
|
|
55
|
-
MockPrincipleTreeLedgerAdapter.prototype = {};
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
mockStateManager,
|
|
59
|
-
mockAdapter,
|
|
60
|
-
mockService,
|
|
61
|
-
MockRuntimeStateManager,
|
|
62
|
-
MockCandidateIntakeService,
|
|
63
|
-
MockPrincipleTreeLedgerAdapter,
|
|
64
|
-
MockCandidateIntakeError,
|
|
65
|
-
};
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Mock modules
|
|
69
|
-
vi.mock('@principles/core/runtime-v2', () => ({
|
|
70
|
-
CandidateIntakeService: MockCandidateIntakeService,
|
|
71
|
-
CandidateIntakeError: MockCandidateIntakeError,
|
|
72
|
-
RuntimeStateManager: MockRuntimeStateManager,
|
|
73
|
-
resolveOutputLanguage: vi.fn().mockReturnValue({ outputLanguage: 'zh-CN' }),
|
|
74
|
-
PrincipleTreeLedgerAdapter: MockPrincipleTreeLedgerAdapter,
|
|
75
|
-
evaluateCandidateAdmissionFromRecord: vi.fn((candidate: { recommendationKind: string; confidence: number | null }) => {
|
|
76
|
-
// Mirror the real implementation for test purposes
|
|
77
|
-
if (candidate.recommendationKind === 'defer') {
|
|
78
|
-
return { decision: 'deferred', reason: 'recommendation_kind_defer_not_actionable', nextAction: 'review_defer_disposition_manually', evidenceStatus: 'unknown' };
|
|
79
|
-
}
|
|
80
|
-
if (candidate.confidence === null) {
|
|
81
|
-
return { decision: 'needs_evidence', reason: 'confidence_missing_on_candidate_record', nextAction: 're_run_diagnosis_to_populate_confidence_or_manual_review', evidenceStatus: 'unknown' };
|
|
82
|
-
}
|
|
83
|
-
if (candidate.confidence < 0.5) {
|
|
84
|
-
return { decision: 'needs_evidence', reason: `confidence_below_threshold:${candidate.confidence.toFixed(2)}<0.5`, nextAction: 'provide_additional_evidence_or_manual_review', evidenceStatus: 'unknown' };
|
|
85
|
-
}
|
|
86
|
-
return { decision: 'admitted', reason: 'cli_partial_check_passed_confidence_and_kind', nextAction: 'none', evidenceStatus: 'unknown' };
|
|
87
|
-
}),
|
|
88
|
-
}));
|
|
89
|
-
|
|
90
|
-
vi.mock('../../src/resolve-workspace.js', () => ({
|
|
91
|
-
resolveWorkspaceDir: vi.fn().mockReturnValue('/tmp/test-workspace'),
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
describe('pd candidate intake', () => {
|
|
95
|
-
let consoleLogSpy: any;
|
|
96
|
-
let consoleErrorSpy: any;
|
|
97
|
-
let exitSpy: any;
|
|
98
|
-
|
|
99
|
-
beforeEach(() => {
|
|
100
|
-
vi.clearAllMocks();
|
|
101
|
-
|
|
102
|
-
// Reset mock implementations
|
|
103
|
-
mockStateManager.getCandidate.mockReset();
|
|
104
|
-
mockStateManager.getArtifact.mockReset();
|
|
105
|
-
mockAdapter.writeProbationEntry.mockReset();
|
|
106
|
-
mockAdapter.existsForCandidate.mockReset();
|
|
107
|
-
mockService.intake.mockReset();
|
|
108
|
-
|
|
109
|
-
// Set default mock implementations
|
|
110
|
-
mockStateManager.initialize.mockResolvedValue(undefined);
|
|
111
|
-
mockStateManager.close.mockResolvedValue(undefined);
|
|
112
|
-
mockAdapter.existsForCandidate.mockReturnValue(null);
|
|
113
|
-
|
|
114
|
-
// Spy on console methods
|
|
115
|
-
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
116
|
-
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
117
|
-
exitSpy = vi.spyOn(process, 'exit').mockImplementation((() => undefined) as () => never);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
afterEach(() => {
|
|
121
|
-
consoleLogSpy.mockRestore();
|
|
122
|
-
consoleErrorSpy.mockRestore();
|
|
123
|
-
exitSpy.mockRestore();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
// Test 1: Happy path JSON
|
|
127
|
-
it('Test 1 (happy path JSON): returns JSON with candidateId, status: consumed, ledgerEntryId', async () => {
|
|
128
|
-
const mockCandidate = {
|
|
129
|
-
candidateId: 'valid-id',
|
|
130
|
-
artifactId: 'artifact-1',
|
|
131
|
-
taskId: 'task-1',
|
|
132
|
-
title: 'Test Principle',
|
|
133
|
-
description: 'Test description',
|
|
134
|
-
status: 'pending',
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const mockEntry = {
|
|
138
|
-
id: 'ledger-entry-1',
|
|
139
|
-
title: 'Test Principle',
|
|
140
|
-
text: 'Test text',
|
|
141
|
-
triggerPattern: 'test pattern',
|
|
142
|
-
action: 'test action',
|
|
143
|
-
status: 'probation',
|
|
144
|
-
evaluability: 'weak_heuristic',
|
|
145
|
-
sourceRef: 'candidate://valid-id',
|
|
146
|
-
artifactRef: 'artifact://artifact-1',
|
|
147
|
-
taskRef: 'task://task-1',
|
|
148
|
-
createdAt: '2026-02-26T00:00:00.000Z',
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
152
|
-
mockService.intake.mockResolvedValue(mockEntry);
|
|
153
|
-
|
|
154
|
-
await handleCandidateIntake({
|
|
155
|
-
candidateId: 'valid-id',
|
|
156
|
-
workspace: '/tmp/test-workspace',
|
|
157
|
-
json: true,
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// Verify service.intake was called
|
|
161
|
-
expect(mockService.intake).toHaveBeenCalledWith('valid-id');
|
|
162
|
-
|
|
163
|
-
// Verify JSON output
|
|
164
|
-
const jsonOutput = consoleLogSpy.mock.calls.find(call => {
|
|
165
|
-
try {
|
|
166
|
-
const parsed = JSON.parse(call[0] as string);
|
|
167
|
-
return parsed.candidateId === 'valid-id' && parsed.status === 'consumed';
|
|
168
|
-
} catch {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
expect(jsonOutput).toBeDefined();
|
|
173
|
-
const parsed = JSON.parse((jsonOutput as [string])[0]);
|
|
174
|
-
expect(parsed.candidateId).toBe('valid-id');
|
|
175
|
-
expect(parsed.status).toBe('consumed');
|
|
176
|
-
expect(parsed.ledgerEntryId).toBe('ledger-entry-1');
|
|
177
|
-
|
|
178
|
-
// Verify exit was not called with 1
|
|
179
|
-
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Test 2: Happy path human-readable
|
|
183
|
-
it('Test 2 (happy path human-readable): prints human-readable format with "Intake complete" message', async () => {
|
|
184
|
-
const mockCandidate = {
|
|
185
|
-
candidateId: 'valid-id',
|
|
186
|
-
artifactId: 'artifact-1',
|
|
187
|
-
taskId: 'task-1',
|
|
188
|
-
title: 'Test Principle',
|
|
189
|
-
description: 'Test description',
|
|
190
|
-
status: 'pending',
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const mockEntry = {
|
|
194
|
-
id: 'ledger-entry-1',
|
|
195
|
-
title: 'Test Principle',
|
|
196
|
-
text: 'Test text',
|
|
197
|
-
status: 'probation',
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
201
|
-
mockService.intake.mockResolvedValue(mockEntry);
|
|
202
|
-
|
|
203
|
-
await handleCandidateIntake({
|
|
204
|
-
candidateId: 'valid-id',
|
|
205
|
-
workspace: '/tmp/test-workspace',
|
|
206
|
-
json: false,
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// Verify human-readable output
|
|
210
|
-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Principle Candidate Intake:'));
|
|
211
|
-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Intake complete.'));
|
|
212
|
-
|
|
213
|
-
// Verify no JSON.parse error (not JSON output)
|
|
214
|
-
const allOutput = consoleLogSpy.mock.calls.map(call => call[0]).join('\n');
|
|
215
|
-
expect(allOutput).toContain('valid-id');
|
|
216
|
-
expect(allOutput).toContain('ledger-entry-1');
|
|
217
|
-
|
|
218
|
-
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// Test 3: Dry-run with complete 11-field entry (JSON output)
|
|
222
|
-
it('Test 3 (dry-run JSON): returns complete 11-field entry without writing to ledger', async () => {
|
|
223
|
-
const mockCandidate = {
|
|
224
|
-
candidateId: 'valid-id',
|
|
225
|
-
artifactId: 'artifact-1',
|
|
226
|
-
taskId: 'task-1',
|
|
227
|
-
title: 'Test Principle',
|
|
228
|
-
description: 'Test description',
|
|
229
|
-
status: 'pending',
|
|
230
|
-
};
|
|
231
|
-
|
|
232
|
-
const mockArtifact = {
|
|
233
|
-
artifactId: 'artifact-1',
|
|
234
|
-
contentJson: JSON.stringify({
|
|
235
|
-
recommendation: {
|
|
236
|
-
title: 'Test Principle',
|
|
237
|
-
text: 'Test text',
|
|
238
|
-
triggerPattern: 'test pattern',
|
|
239
|
-
action: 'test action',
|
|
240
|
-
},
|
|
241
|
-
}),
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
245
|
-
mockStateManager.getArtifact.mockResolvedValue(mockArtifact);
|
|
246
|
-
|
|
247
|
-
await handleCandidateIntake({
|
|
248
|
-
candidateId: 'valid-id',
|
|
249
|
-
workspace: '/tmp/test-workspace',
|
|
250
|
-
dryRun: true,
|
|
251
|
-
json: true,
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
// Verify service.intake was NOT called (dry-run skips service)
|
|
255
|
-
expect(mockService.intake).not.toHaveBeenCalled();
|
|
256
|
-
|
|
257
|
-
// Verify adapter.writeProbationEntry was NOT called
|
|
258
|
-
expect(mockAdapter.writeProbationEntry).not.toHaveBeenCalled();
|
|
259
|
-
|
|
260
|
-
// Verify JSON output has all 11 fields
|
|
261
|
-
const jsonOutput = consoleLogSpy.mock.calls.find(call => {
|
|
262
|
-
try {
|
|
263
|
-
const parsed = JSON.parse(call[0] as string);
|
|
264
|
-
return parsed.id && parsed.title && parsed.sourceRef === 'candidate://valid-id';
|
|
265
|
-
} catch {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
expect(jsonOutput).toBeDefined();
|
|
270
|
-
const entry = JSON.parse((jsonOutput as [string])[0]);
|
|
271
|
-
|
|
272
|
-
// Check all 11 fields exist
|
|
273
|
-
expect(entry.id).toBeDefined();
|
|
274
|
-
expect(entry.title).toBe('Test Principle');
|
|
275
|
-
expect(entry.text).toBe('Test text');
|
|
276
|
-
expect(entry.triggerPattern).toBe('test pattern');
|
|
277
|
-
expect(entry.action).toBe('test action');
|
|
278
|
-
expect(entry.status).toBe('probation');
|
|
279
|
-
expect(entry.evaluability).toBe('weak_heuristic');
|
|
280
|
-
expect(entry.sourceRef).toBe('candidate://valid-id');
|
|
281
|
-
expect(entry.artifactRef).toBe('artifact://artifact-1');
|
|
282
|
-
expect(entry.taskRef).toBe('task://task-1');
|
|
283
|
-
expect(entry.createdAt).toBeDefined();
|
|
284
|
-
|
|
285
|
-
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// Test 3b: Dry-run with human-readable output (covers lines 193-194)
|
|
289
|
-
it('Test 3b (dry-run human-readable): outputs human-readable format without writing', async () => {
|
|
290
|
-
const mockCandidate = {
|
|
291
|
-
candidateId: 'valid-id',
|
|
292
|
-
artifactId: 'artifact-1',
|
|
293
|
-
taskId: 'task-1',
|
|
294
|
-
title: 'Test Principle',
|
|
295
|
-
description: 'Test description',
|
|
296
|
-
status: 'pending',
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
const mockArtifact = {
|
|
300
|
-
artifactId: 'artifact-1',
|
|
301
|
-
contentJson: JSON.stringify({
|
|
302
|
-
recommendation: {
|
|
303
|
-
title: 'Test Principle',
|
|
304
|
-
text: 'Test text',
|
|
305
|
-
},
|
|
306
|
-
}),
|
|
307
|
-
};
|
|
308
|
-
|
|
309
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
310
|
-
mockStateManager.getArtifact.mockResolvedValue(mockArtifact);
|
|
311
|
-
|
|
312
|
-
await handleCandidateIntake({
|
|
313
|
-
candidateId: 'valid-id',
|
|
314
|
-
workspace: '/tmp/test-workspace',
|
|
315
|
-
dryRun: true,
|
|
316
|
-
json: false,
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
// Verify human-readable output (covers lines 193-194)
|
|
320
|
-
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining('Dry-run: would write entry for candidate valid-id'));
|
|
321
|
-
|
|
322
|
-
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
// Test 3c: Dry-run when candidate not found (covers line 165)
|
|
326
|
-
it('Test 3c (dry-run candidate not found): exits with error', async () => {
|
|
327
|
-
mockStateManager.getCandidate.mockResolvedValue(null);
|
|
328
|
-
|
|
329
|
-
await handleCandidateIntake({
|
|
330
|
-
candidateId: 'invalid-id',
|
|
331
|
-
workspace: '/tmp/test-workspace',
|
|
332
|
-
dryRun: true,
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith('Candidate not found: invalid-id');
|
|
336
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
337
|
-
});
|
|
338
|
-
|
|
339
|
-
// Test 3d: Dry-run when artifact not found (covers line 165)
|
|
340
|
-
it('Test 3d (dry-run artifact not found): exits with error', async () => {
|
|
341
|
-
const mockCandidate = {
|
|
342
|
-
candidateId: 'valid-id',
|
|
343
|
-
artifactId: 'artifact-1',
|
|
344
|
-
title: 'Test',
|
|
345
|
-
description: 'Test',
|
|
346
|
-
status: 'pending',
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
350
|
-
mockStateManager.getArtifact.mockResolvedValue(null);
|
|
351
|
-
|
|
352
|
-
await handleCandidateIntake({
|
|
353
|
-
candidateId: 'valid-id',
|
|
354
|
-
workspace: '/tmp/test-workspace',
|
|
355
|
-
dryRun: true,
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith('Artifact not found for candidate: valid-id');
|
|
359
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
// Test 4: Non-existent candidate
|
|
363
|
-
it('Test 4 (non-existent candidate): throws CANDIDATE_NOT_FOUND error', async () => {
|
|
364
|
-
// PRI-442 Stage 4: getCandidate now returns null before service.intake is called.
|
|
365
|
-
// The CLI exits with "Candidate not found" instead of relying on service.intake
|
|
366
|
-
// to throw CANDIDATE_NOT_FOUND.
|
|
367
|
-
mockStateManager.getCandidate.mockResolvedValue(null);
|
|
368
|
-
|
|
369
|
-
await handleCandidateIntake({
|
|
370
|
-
candidateId: 'invalid-id',
|
|
371
|
-
workspace: '/tmp/test-workspace',
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
// Verify error output contains "Candidate not found"
|
|
375
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
376
|
-
expect.stringContaining('Candidate not found')
|
|
377
|
-
);
|
|
378
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
// Test 5: Invalid candidateId (empty string)
|
|
382
|
-
it('Test 5 (invalid candidateId): empty string throws INPUT_INVALID error', async () => {
|
|
383
|
-
// PRI-442 Stage 4: getCandidate is called before service.intake, so we need
|
|
384
|
-
// to mock it to return a valid candidate so service.intake is reached.
|
|
385
|
-
const mockCandidate = {
|
|
386
|
-
candidateId: '',
|
|
387
|
-
artifactId: 'artifact-1',
|
|
388
|
-
taskId: 'task-1',
|
|
389
|
-
title: 'Test',
|
|
390
|
-
description: 'Test',
|
|
391
|
-
status: 'pending',
|
|
392
|
-
};
|
|
393
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
394
|
-
|
|
395
|
-
// Setup: service.intake throws INPUT_INVALID for empty candidateId
|
|
396
|
-
mockService.intake.mockImplementation(() => {
|
|
397
|
-
throw new MockCandidateIntakeError(
|
|
398
|
-
'candidateId must be a non-empty string',
|
|
399
|
-
'INPUT_INVALID',
|
|
400
|
-
{ candidateId: '' }
|
|
401
|
-
);
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
await handleCandidateIntake({
|
|
405
|
-
candidateId: '',
|
|
406
|
-
workspace: '/tmp/test-workspace',
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
410
|
-
expect.stringContaining('INPUT_INVALID')
|
|
411
|
-
);
|
|
412
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
// Test 6: Already consumed candidate (human-readable)
|
|
416
|
-
it('Test 6 (already consumed human-readable): outputs info message and exits successfully', async () => {
|
|
417
|
-
const mockCandidate = {
|
|
418
|
-
candidateId: 'valid-id',
|
|
419
|
-
artifactId: 'artifact-1',
|
|
420
|
-
taskId: 'task-1',
|
|
421
|
-
title: 'Test Principle',
|
|
422
|
-
description: 'Test description',
|
|
423
|
-
status: 'consumed', // Already consumed
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
const mockEntry = {
|
|
427
|
-
id: 'ledger-entry-1',
|
|
428
|
-
title: 'Test Principle',
|
|
429
|
-
text: 'Test text',
|
|
430
|
-
status: 'probation',
|
|
431
|
-
};
|
|
432
|
-
|
|
433
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
434
|
-
mockService.intake.mockResolvedValue(mockEntry);
|
|
435
|
-
|
|
436
|
-
await handleCandidateIntake({
|
|
437
|
-
candidateId: 'valid-id',
|
|
438
|
-
workspace: '/tmp/test-workspace',
|
|
439
|
-
json: false,
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
// Verify info message about already consumed
|
|
443
|
-
const allOutput = consoleLogSpy.mock.calls.map(call => call[0]).join('\n');
|
|
444
|
-
expect(allOutput).toContain('already consumed');
|
|
445
|
-
expect(allOutput).toContain('ledger-entry-1');
|
|
446
|
-
|
|
447
|
-
// Verify exit was not called with 1 (successful exit)
|
|
448
|
-
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
// Test 6b: Already consumed candidate (JSON output, covers line 208)
|
|
452
|
-
it('Test 6b (already consumed JSON): outputs JSON with already_consumed status', async () => {
|
|
453
|
-
const mockCandidate = {
|
|
454
|
-
candidateId: 'valid-id',
|
|
455
|
-
artifactId: 'artifact-1',
|
|
456
|
-
taskId: 'task-1',
|
|
457
|
-
title: 'Test Principle',
|
|
458
|
-
description: 'Test description',
|
|
459
|
-
status: 'consumed', // Already consumed
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
const mockEntry = {
|
|
463
|
-
id: 'ledger-entry-1',
|
|
464
|
-
title: 'Test Principle',
|
|
465
|
-
text: 'Test text',
|
|
466
|
-
status: 'probation',
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
470
|
-
mockService.intake.mockResolvedValue(mockEntry);
|
|
471
|
-
|
|
472
|
-
await handleCandidateIntake({
|
|
473
|
-
candidateId: 'valid-id',
|
|
474
|
-
workspace: '/tmp/test-workspace',
|
|
475
|
-
json: true,
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
// Verify JSON output for already consumed (covers line 208)
|
|
479
|
-
const jsonOutput = consoleLogSpy.mock.calls.find(call => {
|
|
480
|
-
try {
|
|
481
|
-
const parsed = JSON.parse(call[0] as string);
|
|
482
|
-
return parsed.status === 'already_consumed';
|
|
483
|
-
} catch {
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
expect(jsonOutput).toBeDefined();
|
|
488
|
-
const parsed = JSON.parse((jsonOutput as [string])[0]);
|
|
489
|
-
expect(parsed.candidateId).toBe('valid-id');
|
|
490
|
-
expect(parsed.ledgerEntryId).toBe('ledger-entry-1');
|
|
491
|
-
expect(parsed.status).toBe('already_consumed');
|
|
492
|
-
expect(parsed.message).toContain('already consumed');
|
|
493
|
-
|
|
494
|
-
expect(exitSpy).not.toHaveBeenCalledWith(1);
|
|
495
|
-
});
|
|
496
|
-
|
|
497
|
-
// Test 7: Generic error (non-CandidateIntakeError, covers line 247)
|
|
498
|
-
it('Test 7 (generic error): handles non-CandidateIntakeError errors', async () => {
|
|
499
|
-
// PRI-442 Stage 4: getCandidate is called before service.intake, so we need
|
|
500
|
-
// to mock it to return a valid candidate so service.intake is reached.
|
|
501
|
-
const mockCandidate = {
|
|
502
|
-
candidateId: 'valid-id',
|
|
503
|
-
artifactId: 'artifact-1',
|
|
504
|
-
taskId: 'task-1',
|
|
505
|
-
title: 'Test',
|
|
506
|
-
description: 'Test',
|
|
507
|
-
status: 'pending',
|
|
508
|
-
};
|
|
509
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
510
|
-
|
|
511
|
-
// Setup: service.intake throws a generic Error (not CandidateIntakeError)
|
|
512
|
-
mockService.intake.mockImplementation(() => {
|
|
513
|
-
throw new Error('Some unexpected error');
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
await handleCandidateIntake({
|
|
517
|
-
candidateId: 'valid-id',
|
|
518
|
-
workspace: '/tmp/test-workspace',
|
|
519
|
-
});
|
|
520
|
-
|
|
521
|
-
// Verify generic error output (covers line 247)
|
|
522
|
-
// String(err) produces "Error: Some unexpected error"
|
|
523
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
524
|
-
expect.stringContaining('Intake failed: Error: Some unexpected error')
|
|
525
|
-
);
|
|
526
|
-
|
|
527
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
it('guarded transition: UPDATE uses WHERE status = pending for intake path', async () => {
|
|
531
|
-
const mockCandidate = {
|
|
532
|
-
candidateId: 'valid-id',
|
|
533
|
-
artifactId: 'artifact-1',
|
|
534
|
-
taskId: 'task-1',
|
|
535
|
-
title: 'Test Principle',
|
|
536
|
-
description: 'Test description',
|
|
537
|
-
status: 'pending',
|
|
538
|
-
};
|
|
539
|
-
const mockEntry = {
|
|
540
|
-
id: 'ledger-entry-1',
|
|
541
|
-
title: 'Test Principle',
|
|
542
|
-
text: 'Test text',
|
|
543
|
-
status: 'probation',
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
547
|
-
mockService.intake.mockResolvedValue(mockEntry);
|
|
548
|
-
|
|
549
|
-
const capturedPrepareCalls: { sql: string; runArgs: unknown[] }[] = [];
|
|
550
|
-
const originalConnection = mockStateManager.connection;
|
|
551
|
-
mockStateManager.connection = {
|
|
552
|
-
getDb: () => ({
|
|
553
|
-
prepare: (sql: string) => ({
|
|
554
|
-
run: (...args: unknown[]) => {
|
|
555
|
-
capturedPrepareCalls.push({ sql, runArgs: args });
|
|
556
|
-
return { changes: 1 };
|
|
557
|
-
},
|
|
558
|
-
}),
|
|
559
|
-
}),
|
|
560
|
-
};
|
|
561
|
-
|
|
562
|
-
try {
|
|
563
|
-
await handleCandidateIntake({
|
|
564
|
-
candidateId: 'valid-id',
|
|
565
|
-
workspace: '/tmp/test-workspace',
|
|
566
|
-
json: true,
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
const updateCall = capturedPrepareCalls.find(c => c.sql.includes('UPDATE'));
|
|
570
|
-
expect(updateCall).toBeDefined();
|
|
571
|
-
expect(updateCall!.sql).toContain('AND status = ?');
|
|
572
|
-
expect(updateCall!.runArgs[0]).toBe('consumed');
|
|
573
|
-
expect(updateCall!.runArgs[3]).toBe('pending');
|
|
574
|
-
} finally {
|
|
575
|
-
mockStateManager.connection = originalConnection;
|
|
576
|
-
}
|
|
577
|
-
});
|
|
578
|
-
|
|
579
|
-
it('guarded transition: intake fails when candidate is not pending', async () => {
|
|
580
|
-
const mockCandidate = {
|
|
581
|
-
candidateId: 'valid-id',
|
|
582
|
-
artifactId: 'artifact-1',
|
|
583
|
-
taskId: 'task-1',
|
|
584
|
-
title: 'Test Principle',
|
|
585
|
-
description: 'Test description',
|
|
586
|
-
status: 'pending',
|
|
587
|
-
};
|
|
588
|
-
const mockEntry = {
|
|
589
|
-
id: 'ledger-entry-1',
|
|
590
|
-
title: 'Test Principle',
|
|
591
|
-
text: 'Test text',
|
|
592
|
-
status: 'probation',
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
596
|
-
mockService.intake.mockResolvedValue(mockEntry);
|
|
597
|
-
|
|
598
|
-
const originalConnection = mockStateManager.connection;
|
|
599
|
-
mockStateManager.connection = {
|
|
600
|
-
getDb: () => ({
|
|
601
|
-
prepare: (sql: string) => ({
|
|
602
|
-
run: () => ({ changes: 0 }),
|
|
603
|
-
}),
|
|
604
|
-
}),
|
|
605
|
-
};
|
|
606
|
-
|
|
607
|
-
try {
|
|
608
|
-
await handleCandidateIntake({
|
|
609
|
-
candidateId: 'valid-id',
|
|
610
|
-
workspace: '/tmp/test-workspace',
|
|
611
|
-
json: true,
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('Guarded transition failed'));
|
|
615
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
616
|
-
} finally {
|
|
617
|
-
mockStateManager.connection = originalConnection;
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
|
|
621
|
-
// PRI-442 Stage 4: admission gate bypass tests
|
|
622
|
-
describe('admission gate bypass prevention (PRI-442 Stage 4)', () => {
|
|
623
|
-
it('refuses intake when recommendationKind is defer', async () => {
|
|
624
|
-
const mockCandidate = {
|
|
625
|
-
candidateId: 'defer-cand',
|
|
626
|
-
artifactId: 'artifact-1',
|
|
627
|
-
taskId: 'task-1',
|
|
628
|
-
title: 'Deferred candidate',
|
|
629
|
-
description: 'Should not be intakeable',
|
|
630
|
-
status: 'pending',
|
|
631
|
-
recommendationKind: 'defer',
|
|
632
|
-
confidence: 0.9,
|
|
633
|
-
};
|
|
634
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
635
|
-
|
|
636
|
-
await handleCandidateIntake({
|
|
637
|
-
candidateId: 'defer-cand',
|
|
638
|
-
workspace: '/tmp/test-workspace',
|
|
639
|
-
json: true,
|
|
640
|
-
});
|
|
641
|
-
|
|
642
|
-
// Should NOT call service.intake
|
|
643
|
-
expect(mockService.intake).not.toHaveBeenCalled();
|
|
644
|
-
// Should output refused status
|
|
645
|
-
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
646
|
-
expect.stringContaining('"status": "refused"')
|
|
647
|
-
);
|
|
648
|
-
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
649
|
-
expect.stringContaining('"admissionDecision": "deferred"')
|
|
650
|
-
);
|
|
651
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
it('refuses intake when confidence is below threshold', async () => {
|
|
655
|
-
const mockCandidate = {
|
|
656
|
-
candidateId: 'low-conf-cand',
|
|
657
|
-
artifactId: 'artifact-1',
|
|
658
|
-
taskId: 'task-1',
|
|
659
|
-
title: 'Low confidence candidate',
|
|
660
|
-
description: 'Should not be intakeable',
|
|
661
|
-
status: 'pending',
|
|
662
|
-
recommendationKind: 'principle',
|
|
663
|
-
confidence: 0.3,
|
|
664
|
-
};
|
|
665
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
666
|
-
|
|
667
|
-
await handleCandidateIntake({
|
|
668
|
-
candidateId: 'low-conf-cand',
|
|
669
|
-
workspace: '/tmp/test-workspace',
|
|
670
|
-
json: false,
|
|
671
|
-
});
|
|
672
|
-
|
|
673
|
-
expect(mockService.intake).not.toHaveBeenCalled();
|
|
674
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
675
|
-
expect.stringContaining('Admission gate refused')
|
|
676
|
-
);
|
|
677
|
-
expect(consoleErrorSpy).toHaveBeenCalledWith(
|
|
678
|
-
expect.stringContaining('needs_evidence')
|
|
679
|
-
);
|
|
680
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
it('refuses intake when confidence is null (rc-3 fail loud)', async () => {
|
|
684
|
-
const mockCandidate = {
|
|
685
|
-
candidateId: 'null-conf-cand',
|
|
686
|
-
artifactId: 'artifact-1',
|
|
687
|
-
taskId: 'task-1',
|
|
688
|
-
title: 'Null confidence candidate',
|
|
689
|
-
description: 'Should not be intakeable',
|
|
690
|
-
status: 'pending',
|
|
691
|
-
recommendationKind: 'principle',
|
|
692
|
-
confidence: null,
|
|
693
|
-
};
|
|
694
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
695
|
-
|
|
696
|
-
await handleCandidateIntake({
|
|
697
|
-
candidateId: 'null-conf-cand',
|
|
698
|
-
workspace: '/tmp/test-workspace',
|
|
699
|
-
json: true,
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
expect(mockService.intake).not.toHaveBeenCalled();
|
|
703
|
-
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
704
|
-
expect.stringContaining('confidence_missing_on_candidate_record')
|
|
705
|
-
);
|
|
706
|
-
expect(exitSpy).toHaveBeenCalledWith(1);
|
|
707
|
-
});
|
|
708
|
-
|
|
709
|
-
it('allows intake when candidate passes admission gate', async () => {
|
|
710
|
-
const mockCandidate = {
|
|
711
|
-
candidateId: 'admitted-cand',
|
|
712
|
-
artifactId: 'artifact-1',
|
|
713
|
-
taskId: 'task-1',
|
|
714
|
-
title: 'Admitted candidate',
|
|
715
|
-
description: 'Should be intakeable',
|
|
716
|
-
status: 'pending',
|
|
717
|
-
recommendationKind: 'principle',
|
|
718
|
-
confidence: 0.8,
|
|
719
|
-
};
|
|
720
|
-
mockStateManager.getCandidate.mockResolvedValue(mockCandidate);
|
|
721
|
-
mockService.intake.mockResolvedValue({ id: 'entry-1', title: 'Test', text: 'Test', status: 'probation' });
|
|
722
|
-
|
|
723
|
-
await handleCandidateIntake({
|
|
724
|
-
candidateId: 'admitted-cand',
|
|
725
|
-
workspace: '/tmp/test-workspace',
|
|
726
|
-
json: true,
|
|
727
|
-
});
|
|
728
|
-
|
|
729
|
-
expect(mockService.intake).toHaveBeenCalledWith('admitted-cand');
|
|
730
|
-
});
|
|
731
|
-
});
|
|
732
|
-
});
|