Files
fusion/packages/engine/src/merger-errors.ts
gsxdsm 9a34862586 refactor: package code organization waves 3–5 (#2148)
## Summary

Waves 3–5 of package code organization (plan:
`docs/plans/2026-07-14-001-refactor-package-code-organization-plan.md`).
Behavior-preserving peels after #2139 and #2143.

### Wave 3 — Merger + heartbeat recovery
- **`merger-errors.ts`** — verification/abort error classes
- **`merger-owned-landed.ts`** — ownership classification +
`Fusion-Task-Id` trailer
- **`merger-conflict-resolution.ts`** — conflict classify/auto-resolve
- **`agent-heartbeat-error-recovery.ts`** — durable error-recovery
budget helpers

### Wave 4 — Self-healing + dashboard API
- **`self-healing-constants.ts`** — public timing/budget constants
- **`self-healing-branch.ts`** — `isBranchAheadOfBase`
- **`app/api/client.ts`** — `api` / `ApiRequestError` / `buildApiUrl` /
`proxyApi`
- **`app/api/health.ts`** — health, engine status, updates +
`withProjectId`

### Wave 5 — Types tracking + merger parse + task CRUD
- **`types/task-tracking.ts`** — PR/issue/GitHub/GitLab tracking
contracts
- **`merger-git-parse.ts`** — `parseFailingFilesFromOutput`,
`parsePorcelainZ`, `parseShortstatSummary`
- **`app/api/tasks.ts`** — task list/detail/create/update/move client
surface
- Line-count baselines ratcheted down for `merger.ts`, `types.ts`,
`legacy.ts`

Public import paths stay on parent modules / `legacy.ts` / package
barrels via re-exports.

## Test plan
- [x] core/engine/dashboard typecheck (including `tsconfig.app.json`)
- [x] eslint on touched modules
- [x] `parse-porcelain-z` + merger parseFailing/getBranchChanged tests
- [x] dashboard `api-tasks` + legacy-prinfo/pr-types (69)
- [ ] CI merge gate

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added dashboard API support for task listing/detail, archiving,
creation, review updates, duplicate detection, bulk model updates,
moving tasks, and overlap repair.
- Added health/engine status and refresh/start controls, plus update
checking.

- **Bug Fixes**
- Improved dashboard API handling for non-JSON/HTML responses with
clearer errors, better URL routing for remote nodes, and project-scoped
queries.
- Strengthened automated recovery for heartbeat error/model-unavailable
scenarios and safer merge-conflict classification/auto-resolution.

- **Tests**
- Updated merge-conflict resolution and lifecycle test mocks to match
the updated git command behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-16 00:01:17 -07:00

48 lines
1.4 KiB
TypeScript

/**
* FNXC:CodeOrganization 2026-07-15-14:30:
* Merger error classes and abort helper peeled from merger.ts.
*/
import type { VerificationResult } from "./verification-utils.js";
export class VerificationError extends Error {
constructor(
message: string,
public readonly verificationResult: VerificationResult,
) {
super(message);
this.name = "VerificationError";
}
}
/** Raised when a merge is explicitly cancelled (for example engine shutdown). */
export class MergeAbortedError extends Error {
constructor(message: string) {
super(message);
this.name = "MergeAbortedError";
}
}
/**
* Raised when fix agent made no changes and the failing test files are all
* outside the branch's diff. This signals that the failure is pre-existing on
* the base branch (e.g. a flaky engine test) and retrying cannot help.
*
* The merger catches this and marks the task `failed` with a clear error
* message, bypassing limbo recovery so the user sees an actionable status.
*/
export class OutOfScopeVerificationError extends Error {
constructor(
message: string,
public readonly failingFiles: string[],
public readonly branchFiles: string[],
) {
super(message);
this.name = "OutOfScopeVerificationError";
}
}
export function throwIfAborted(signal: AbortSignal | undefined, taskId: string): void {
if (!signal?.aborted) return;
throw new MergeAbortedError(`Merge aborted for ${taskId}: engine shutdown requested`);
}