-
Notifications
You must be signed in to change notification settings - Fork 226
feat: error-interception-middleware (1/3) #1121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
myk1yt
wants to merge
8
commits into
Zoo-Code-Org:main
Choose a base branch
from
myk1yt:pr/b01-error-contracts-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8491155
feat(error): define error contracts and classification types
877b373
chore: remove temp file progress.txt
9da4617
Merge branch 'main' into pr/b01-error-contracts-v2
myk1yt 9a2e6f2
test(e2e): add error-interception contract suite
f1c0dd7
fix(test): resolve ESLint error and fix workspaceRoot path in error-i…
6079184
fix(test): use pathToFileURL for cross-platform dynamic import compat…
40d07ba
fix(e2e): wrap loadModuleFromBundle in try-catch for graceful skip
b6ed9c0
fix(vscode-e2e): avoid importing main extension bundle in error-inter…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| import * as assert from "assert" | ||
| import * as path from "path" | ||
| import * as fs from "fs" | ||
|
|
||
| import { setDefaultSuiteTimeout } from "./test-utils" | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Error Interception — bundled-artifact import smoke test | ||
| // --------------------------------------------------------------------------- | ||
| // | ||
| // Scope: This suite is intentionally minimal. It proves ONE thing — that the | ||
| // error-interception contract (classifyError / classifyToolResult / | ||
| // ERROR_PATTERNS) survives bundling and is importable from the real, built | ||
| // extension artifact that the VS Code extension host loads. | ||
| // | ||
| // Detailed classifier behavior (pattern ordering, classification accuracy, | ||
| // parameter sanitization, metadata redaction, fallback/UNCLASSIFIED behavior) | ||
| // is covered by the Vitest unit suite at: | ||
| // src/core/tools/error-interception/__tests__/ErrorClassifier.spec.ts | ||
| // | ||
| // How the module is loaded: | ||
| // The e2e workspace does not use TS project references into src/, so a | ||
| // static import would fail `check-types`. Instead we locate the built | ||
| // extension entry (dist/extension.js, produced by `pnpm -w bundle` in the | ||
| // test:ci pipeline) and dynamically import it — the same artifact the host | ||
| // loads. If the bundle is absent (e.g. a bare `check-types` run without a | ||
| // build), the suite skips cleanly rather than failing on an infrastructure | ||
| // gap. | ||
|
|
||
| interface ErrorClassificationLike { | ||
| category: string | ||
| patternId: string | ||
| confidence: string | ||
| retryPolicy: string | ||
| facts: Readonly<Record<string, unknown>> | ||
| } | ||
|
|
||
| interface InterceptionSignalLike { | ||
| source: string | ||
| stage: string | ||
| taskId: string | ||
| toolCallId?: string | ||
| toolName?: string | ||
| error?: unknown | ||
| result?: { type?: string; status?: string; error?: unknown; text?: string; [key: string]: unknown } | ||
| metadata: Readonly<Record<string, unknown>> | ||
| } | ||
|
|
||
| interface ErrorInterceptionModule { | ||
| classifyError: (signal: InterceptionSignalLike) => ErrorClassificationLike | ||
| classifyToolResult: ( | ||
| result: InterceptionSignalLike["result"], | ||
| taskId: string, | ||
| toolCallId?: string, | ||
| ) => ErrorClassificationLike | ||
| ERROR_PATTERNS: Array<{ id: string; category: string; priority: number }> | ||
| } | ||
|
|
||
| function findBuiltExtensionEntry(workspaceRoot: string): string | undefined { | ||
| const candidates = [ | ||
| path.join(workspaceRoot, "src", "dist", "extension.js"), | ||
| path.join(workspaceRoot, "dist", "extension.js"), | ||
| path.join(workspaceRoot, "src", "dist", "extension.cjs"), | ||
| ] | ||
| return candidates.find((p) => fs.existsSync(p)) | ||
| } | ||
|
|
||
| async function loadModuleFromBundle(workspaceRoot: string, entry: string): Promise<ErrorInterceptionModule | undefined> { | ||
| // Load the built bundle via dynamic import. The bundle may surface the | ||
| // error-interception contract as an explicit re-export; otherwise we fall | ||
| // back to importing the submodule path within the same output directory. | ||
| const bundle = (await import(entry)) as { __errorInterception?: ErrorInterceptionModule } & Record<string, unknown> | ||
|
|
||
| if (bundle.__errorInterception) { | ||
| return bundle.__errorInterception | ||
| } | ||
|
|
||
| const subPath = path.join(workspaceRoot, "src", "dist", "core", "tools", "error-interception", "index.js") | ||
| if (fs.existsSync(subPath)) { | ||
| return (await import(subPath)) as ErrorInterceptionModule | ||
| } | ||
|
|
||
| return undefined | ||
| } | ||
|
|
||
| suite("Error Interception — Bundled Artifact Smoke Test (e2e)", function () { | ||
| setDefaultSuiteTimeout(this) | ||
|
|
||
| let ei: ErrorInterceptionModule | undefined | ||
|
|
||
| suiteSetup(async function () { | ||
| // __dirname = apps/vscode-e2e/out/suite at runtime. | ||
| // 4 levels up: suite -> out -> vscode-e2e -> apps -> workspace root. | ||
| const workspaceRoot = path.resolve(__dirname, "..", "..", "..", "..") | ||
| const entry = findBuiltExtensionEntry(workspaceRoot) | ||
|
|
||
| if (!entry) { | ||
| // The bundled extension is not present (no `pnpm -w bundle` run). | ||
| // This is an environment gap, not a contract regression — skip. | ||
| console.warn( | ||
| "[error-interception e2e] built extension bundle not found; " + | ||
| "run `pnpm -w bundle` before `test:run` to enable this suite.", | ||
| ) | ||
| return | ||
| } | ||
|
|
||
| ei = await loadModuleFromBundle(workspaceRoot, entry) | ||
|
|
||
| if (!ei) { | ||
| console.warn( | ||
| "[error-interception e2e] error-interception module not exposed by the built bundle; " + | ||
| "skipping contract assertions.", | ||
| ) | ||
| } | ||
| }) | ||
|
|
||
| setup(function () { | ||
| if (!ei) { | ||
| this.skip() | ||
| } | ||
| }) | ||
|
|
||
| test("bundled artifact exports the error-interception contract", () => { | ||
| assert.ok(ei, "error-interception module must be importable from the built bundle") | ||
| assert.strictEqual(typeof ei!.classifyError, "function", "classifyError must be a function") | ||
| assert.strictEqual(typeof ei!.classifyToolResult, "function", "classifyToolResult must be a function") | ||
| assert.ok(Array.isArray(ei!.ERROR_PATTERNS), "ERROR_PATTERNS must be an array") | ||
| assert.ok(ei!.ERROR_PATTERNS.length > 0, "pattern DB must not be empty") | ||
| }) | ||
|
|
||
| test("bundled classifier classifies a FILE_NOT_FOUND tool result end-to-end", () => { | ||
| const c = ei!.classifyError({ | ||
| source: "tool_result", | ||
| stage: "result", | ||
| taskId: "e2e-error-interception-smoke", | ||
| toolCallId: "e2e-tool-call-1", | ||
| toolName: "read_file", | ||
| result: { | ||
| type: "tool_result", | ||
| status: "error", | ||
| text: "File not found: /nonexistent/path/that/does/not/exist.txt", | ||
| }, | ||
| metadata: { status: "error", fileNotFound: true }, | ||
| }) | ||
|
|
||
| assert.strictEqual(c.category, "FILE_NOT_FOUND") | ||
| assert.ok(c.patternId.length > 0, "patternId must identify the matched pattern") | ||
| assert.strictEqual(c.facts.errorSource, "tool_result") | ||
| }) | ||
| }) | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.