@oneharness/sdk 0.4.4 → 0.4.6

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/README.md CHANGED
@@ -11,7 +11,7 @@ const checked: RunReport = RunReportSchema.parse(report);
11
11
  console.log(checked.results[0]?.text, checked.results[0]?.usage.input_tokens);
12
12
  ```
13
13
 
14
- The complete client surface is `run`, `runStream`, `list`, `detect`, `history`, `historyList`, and `historyWatch`. Both streaming methods return async iterators:
14
+ The complete client surface includes `run`, `runMock`, `runStream`, `list`, `detect`, `history`, `historyList`, and `historyWatch`. `runMock` uses the deterministic responder shipped in the CLI; see [Testing patterns](../../docs/testing-patterns.md). Both streaming methods return async iterators:
15
15
 
16
16
  ```ts
17
17
  for await (const envelope of oneharness.runStream({
package/dist/index.d.ts CHANGED
@@ -28,6 +28,13 @@ export type OneHarnessOptions = {
28
28
  executableArgs?: readonly string[];
29
29
  env?: Readonly<Record<string, string>>;
30
30
  };
31
+ /** Script for the shipped deterministic provider substitute. */
32
+ export type MockHarnessScript = {
33
+ stdout?: string;
34
+ stderr?: string;
35
+ exitCode?: number;
36
+ latencyMs?: number;
37
+ };
31
38
  /** A non-zero exit from the oneharness subprocess. */
32
39
  export declare class OneHarnessProcessError extends Error {
33
40
  readonly exitCode: number | null;
@@ -42,6 +49,7 @@ export declare class OneHarness {
42
49
  private readonly options;
43
50
  constructor(options?: OneHarnessOptions);
44
51
  run(options: RunOptions): Promise<RunReport>;
52
+ runMock(harness: string, options: RunOptions, script?: MockHarnessScript): Promise<RunReport>;
45
53
  runStream(options: RunOptions): AsyncGenerator<RunStreamEnvelope>;
46
54
  list(): Promise<HarnessInfo[]>;
47
55
  detect(harnesses?: readonly string[]): Promise<Detection[]>;
package/dist/index.js CHANGED
@@ -194,6 +194,24 @@ export class OneHarness {
194
194
  const value = await invokeWith(this.options, args, input.cwd, true);
195
195
  return parseContract(RunReportSchema, value, "invalid oneharness run contract");
196
196
  }
197
+ async runMock(harness, options, script = {}) {
198
+ if (harness.length === 0)
199
+ throw new Error("mock harness must not be empty");
200
+ const input = parseContract(RunOptionsSchema, options, "invalid oneharness run options");
201
+ const env = { ...(input.env ?? {}) };
202
+ if (script.stdout !== undefined)
203
+ env.MOCK_STDOUT = script.stdout;
204
+ if (script.stderr !== undefined)
205
+ env.MOCK_STDERR = script.stderr;
206
+ if (script.exitCode !== undefined)
207
+ env.MOCK_EXIT = String(script.exitCode);
208
+ if (script.latencyMs !== undefined)
209
+ env.MOCK_SLEEP_MS = String(script.latencyMs);
210
+ const args = runArguments({ ...input, harnesses: [harness], env }, false);
211
+ args.push("--mock-harness", harness);
212
+ const value = await invokeWith(this.options, args, input.cwd, true);
213
+ return parseContract(RunReportSchema, value, "invalid oneharness run contract");
214
+ }
197
215
  runStream(options) {
198
216
  const input = parseContract(RunOptionsSchema, options, "invalid oneharness run options");
199
217
  return invokeStreamWith(this.options, runArguments(input, true), RunStreamEnvelopeSchema, "invalid oneharness run stream contract", input.cwd);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneharness/sdk",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Typed Node.js SDK for oneharness",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -19,7 +19,7 @@
19
19
  "node": ">=20"
20
20
  },
21
21
  "dependencies": {
22
- "oneharness-cli": "0.4.4",
22
+ "oneharness-cli": "0.4.6",
23
23
  "zod": "^4.4.3"
24
24
  }
25
25
  }