Files
ci/src/core/error-recovery.test.ts
T
CI fb3f1df13e release(v0.4.0): purge learnship, migrate .planning→.ci, fix backends, add test coverage
- Remove all learnship references: Decision.learnship_equivalent field,
  agent persona prompts, opencode.json permissions, test fixtures
- Migrate verification layers from .planning/ to .ci/: structural
  checks .ci/ dir + ROADMAP.md, behavioral checks ROADMAP.md
- Fix ollama-local: remove sync require+curl blocking, use async
  fetchAvailableModels() in callModel
- Fix opencode.json: use __OPENCODE_DIR__ template tokens, remove
  legacy learnship permission entries
- Remove duplicate install script from package.json (keep postinstall)
- Fix quality any-regex false positives (target type annotations only)
- Add backends test coverage: backends.test.ts, tool-registry.test.ts
- Version bump 0.3.0 → 0.4.0
- Artifacts module: rename .planning→.ci internal paths
- Remove dead TODO_PATTERN/FIXME_PATTERN constants

---ci---
phase: 3
milestone: v0.4
status: complete
requirements:
  covered: [REQ-09, REQ-10, REQ-11, REQ-13, REQ-14, REQ-17]
  partial: []
decisions:
  - id: D-001
    decision: purge all learnship references from codebase
    rationale: project is CI-only, learnship is no longer a dependency
    confidence: 0.99
    category: scope
    alternatives: [keep for historical reference]
  - id: D-002
    decision: migrate verification from .planning/ to .ci/ paths
    rationale: .planning/ is removed schema, all current state lives in .ci/
    confidence: 0.95
    category: architecture
    alternatives: [keep dual-path support]
  - id: D-003
    decision: use __OPENCODE_DIR__ template tokens in opencode.json
    rationale: hardcoded ~ paths fail in containers and non-standard homes
    confidence: 0.90
    category: implementation_approach
    alternatives: [keep tilde expansion]
---/ci---
2026-05-29 16:18:30 +00:00

90 lines
3.3 KiB
TypeScript

import * as fs from "node:fs";
import * as path from "node:path";
import * as os from "node:os";
import { ErrorRecovery } from "../core/error-recovery.js";
import { DEFAULT_CI_CONFIG } from "../types/config.js";
describe("ErrorRecovery", () => {
let tempDir: string;
let recovery: ErrorRecovery;
beforeEach(() => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "ci-recovery-test-"));
fs.mkdirSync(path.join(tempDir, ".ci"), { recursive: true });
recovery = new ErrorRecovery(DEFAULT_CI_CONFIG, tempDir);
});
afterEach(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});
describe("recoverFromFailure", () => {
it("recommends retry for verification failures within retry limit", async () => {
const result = await recovery.recoverFromFailure("Test failed", 1, "verify", 1);
expect(result.recovered).toBe(true);
expect(result.strategy).toBe("retry");
expect(result.attempts).toBe(1);
});
it("escalates after max verification retries exceeded", async () => {
const result = await recovery.recoverFromFailure("Test failed", 1, "verify", 4);
expect(result.recovered).toBe(false);
expect(result.strategy).toBe("escalate");
});
it("recommends plan revision for plan stage failures", async () => {
const result = await recovery.recoverFromFailure("Plan issues found", 1, "plan", 1);
expect(result.recovered).toBe(true);
expect(result.strategy).toBe("plan_revision");
});
it("escalates after max plan revisions", async () => {
await recovery.recoverFromFailure("Plan issues", 1, "plan", 1);
await recovery.recoverFromFailure("Plan issues", 1, "plan", 1);
await recovery.recoverFromFailure("Plan issues", 1, "plan", 1);
const result = await recovery.recoverFromFailure("Plan issues", 1, "plan", 1);
expect(result.recovered).toBe(false);
expect(result.strategy).toBe("escalate");
});
it("escalates for non-recoverable stages", async () => {
const result = await recovery.recoverFromFailure("Unknown error", 1, "specify", 1);
expect(result.recovered).toBe(false);
expect(result.strategy).toBe("escalate");
});
});
describe("rollback", () => {
it("returns recovered result with rollback strategy", async () => {
const result = await recovery.rollback(1, "User-requested rollback");
expect(result.recovered).toBe(true);
expect(result.strategy).toBe("rollback");
expect(result.message).toContain("phase 1");
});
});
describe("canAutoDebug", () => {
it("returns true when confidence meets threshold", () => {
expect(recovery.canAutoDebug("error", 0.6)).toBe(true);
expect(recovery.canAutoDebug("error", 0.8)).toBe(true);
expect(recovery.canAutoDebug("error", 1.0)).toBe(true);
});
it("returns false when confidence is below threshold", () => {
expect(recovery.canAutoDebug("error", 0.59)).toBe(false);
expect(recovery.canAutoDebug("error", 0.3)).toBe(false);
});
});
describe("getMaxRetries", () => {
it("returns the configured max verification retries", () => {
expect(recovery.getMaxRetries()).toBe(2);
});
});
describe("getMaxRevisions", () => {
it("returns the configured max revision iterations", () => {
expect(recovery.getMaxRevisions()).toBe(3);
});
});
});