-
Notifications
You must be signed in to change notification settings - Fork 448
feat: [ENG-2238] AutoHarness V2 HarnessContext + module contract #494
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,9 @@ | ||
| /** | ||
| * AutoHarness V2 core-domain barrel. | ||
| * | ||
| * Re-exports every harness domain type so consumers import from a | ||
| * single path: `import type {HarnessContext, HarnessModule} from | ||
| * '.../core/domain/harness'`. | ||
| */ | ||
|
|
||
| export * from './types.js' |
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
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,125 @@ | ||
| import {expect} from 'chai' | ||
| import {expectTypeOf} from 'expect-type' | ||
|
|
||
| import type { | ||
| HarnessContext, | ||
| HarnessContextEnv, | ||
| HarnessContextTools, | ||
| HarnessLoadResult, | ||
| HarnessModule, | ||
| HarnessVersion, | ||
| } from '../../../../src/agent/core/domain/harness/index.js' | ||
| import type {CurateResult} from '../../../../src/agent/core/interfaces/i-curate-service.js' | ||
|
|
||
| describe('HarnessContext + module contract', () => { | ||
| describe('HarnessModule', () => { | ||
| it('requires `meta` and makes `curate` / `query` optional', () => { | ||
| // Minimal valid module: just meta. | ||
| const minimal: HarnessModule = { | ||
| meta: () => ({ | ||
| capabilities: [], | ||
| commandType: 'curate', | ||
| projectPatterns: [], | ||
| version: 1, | ||
| }), | ||
| } | ||
| expect(minimal.curate).to.equal(undefined) | ||
| expect(minimal.query).to.equal(undefined) | ||
| expectTypeOf(minimal.meta).returns.toMatchTypeOf<{commandType: string}>() | ||
| }) | ||
|
|
||
| it('rejects a module missing `meta` at compile time', () => { | ||
| // @ts-expect-error — meta is required | ||
| const broken: HarnessModule = {curate: async () => ({} as CurateResult)} | ||
| expect(broken).to.exist | ||
| }) | ||
| }) | ||
|
|
||
| describe('HarnessContext readonly enforcement (compile-time only)', () => { | ||
| // `readonly` is a TypeScript-level invariant. The tests below pass | ||
| // iff the `@ts-expect-error` directives are consumed (i.e., TS would | ||
| // report an error without them). Runtime writes still execute — | ||
| // that's fine; the guarantee we're testing is the compile-time one, | ||
| // and Phase 3 Task 3.2's module builder enforces runtime frozenness | ||
| // via `Object.freeze` separately. | ||
|
|
||
| it('rejects reassigning `ctx.env`', () => { | ||
| const ctx: HarnessContext = { | ||
| abort: new AbortController().signal, | ||
| env: {commandType: 'curate', projectType: 'typescript', workingDirectory: '/'}, | ||
| tools: {} as HarnessContextTools, | ||
| } | ||
| const replacement: HarnessContextEnv = { | ||
| commandType: 'chat', | ||
| projectType: 'generic', | ||
| workingDirectory: '/other', | ||
| } | ||
| // @ts-expect-error — env is readonly on HarnessContext | ||
| ctx.env = replacement | ||
| expect(ctx).to.exist | ||
| }) | ||
|
|
||
| it('rejects reassigning `env.workingDirectory`', () => { | ||
| const env: HarnessContextEnv = { | ||
| commandType: 'curate', | ||
| projectType: 'typescript', | ||
| workingDirectory: '/tmp', | ||
| } | ||
| // @ts-expect-error — workingDirectory is readonly | ||
| env.workingDirectory = '/elsewhere' | ||
| expect(env).to.exist | ||
| }) | ||
|
|
||
| it('rejects reassigning `tools.curate`', () => { | ||
| const tools: HarnessContextTools = { | ||
| curate: (async () => ({}) as CurateResult) as HarnessContextTools['curate'], | ||
|
danhdoan marked this conversation as resolved.
danhdoan marked this conversation as resolved.
|
||
| readFile: (async () => ({}) as never) as HarnessContextTools['readFile'], | ||
| } | ||
| const replacement = (async () => ({}) as CurateResult) as HarnessContextTools['curate'] | ||
| // @ts-expect-error — curate is readonly | ||
| tools.curate = replacement | ||
| expect(tools).to.exist | ||
| }) | ||
| }) | ||
|
|
||
| describe('HarnessLoadResult discriminated union', () => { | ||
| it('narrows to `module` + `version` when `loaded === true`', () => { | ||
| const result: HarnessLoadResult = { | ||
| loaded: true, | ||
| module: { | ||
| meta: () => ({ | ||
| capabilities: [], | ||
| commandType: 'curate', | ||
| projectPatterns: [], | ||
| version: 1, | ||
| }), | ||
| }, | ||
| version: {} as HarnessVersion, | ||
| } | ||
|
|
||
| if (result.loaded) { | ||
| expectTypeOf(result.module).toEqualTypeOf<HarnessModule>() | ||
| expectTypeOf(result.version).toEqualTypeOf<HarnessVersion>() | ||
| } | ||
| }) | ||
|
|
||
| it('narrows to `reason` when `loaded === false`', () => { | ||
| const result: HarnessLoadResult = {loaded: false, reason: 'no-version'} | ||
|
|
||
| if (!result.loaded) { | ||
| expectTypeOf(result.reason).toEqualTypeOf< | ||
| 'meta-invalid' | 'meta-threw' | 'no-version' | 'syntax' | ||
| >() | ||
| } | ||
| }) | ||
|
|
||
| it('does NOT expose `module` on the `loaded: false` variant', () => { | ||
| // Type-level assertion: the failure variant's keys exclude `module`. | ||
| // Extracting the failure variant from the union and checking its | ||
| // keys is safer than trying `@ts-expect-error` inside a runtime | ||
| // narrowing block, which is sensitive to unrelated TS lenience. | ||
| type FailureVariant = Extract<HarnessLoadResult, {loaded: false}> | ||
| expectTypeOf<keyof FailureVariant>().toEqualTypeOf<'loaded' | 'reason'>() | ||
| }) | ||
| }) | ||
| }) | ||
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.