@leitwerk-dev/test-support 0.2.1 → 0.3.0

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.
Files changed (59) hide show
  1. package/dist/{chunk-ECAWLVYB.js → chunk-E4Y7XND5.js} +3 -1
  2. package/dist/chunk-E4Y7XND5.js.map +1 -0
  3. package/dist/chunk-KJVNI2UP.js +17 -0
  4. package/dist/chunk-KJVNI2UP.js.map +1 -0
  5. package/dist/{chunk-2PCDTYVH.js → chunk-OE4NHDVS.js} +10 -4
  6. package/dist/chunk-OE4NHDVS.js.map +1 -0
  7. package/dist/chunk-P2FF4AP7.js +72 -0
  8. package/dist/chunk-P2FF4AP7.js.map +1 -0
  9. package/dist/chunk-RY6Y6V5E.js +54 -0
  10. package/dist/chunk-RY6Y6V5E.js.map +1 -0
  11. package/dist/extension-integration-harness.d.ts +357 -0
  12. package/dist/extension-integration-harness.d.ts.map +1 -0
  13. package/dist/fixtures.d.ts +2 -0
  14. package/dist/fixtures.d.ts.map +1 -1
  15. package/dist/fixtures.js +53 -0
  16. package/dist/fixtures.js.map +1 -1
  17. package/dist/index.d.ts +2 -19
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +4 -67
  20. package/dist/index.js.map +1 -1
  21. package/dist/integration.d.ts +1 -0
  22. package/dist/integration.d.ts.map +1 -1
  23. package/dist/integration.js +564 -2
  24. package/dist/integration.js.map +1 -1
  25. package/dist/local-git.d.ts.map +1 -1
  26. package/dist/local-git.js.map +1 -1
  27. package/dist/observations.d.ts +7 -0
  28. package/dist/observations.d.ts.map +1 -0
  29. package/dist/process-fixtures.d.ts +56 -0
  30. package/dist/process-fixtures.d.ts.map +1 -0
  31. package/dist/process.d.ts +440 -0
  32. package/dist/process.d.ts.map +1 -0
  33. package/dist/process.js +484 -0
  34. package/dist/process.js.map +1 -0
  35. package/dist/stub-worker-entry.js +1 -1
  36. package/dist/supported-question-fixtures.d.ts +96 -0
  37. package/dist/supported-question-fixtures.d.ts.map +1 -0
  38. package/dist/test-capability.d.ts +9 -0
  39. package/dist/test-capability.d.ts.map +1 -0
  40. package/dist/worker-testing/in-process-worker-spawn.d.ts +2 -0
  41. package/dist/worker-testing/in-process-worker-spawn.d.ts.map +1 -1
  42. package/dist/worker-testing/index.js +2 -2
  43. package/dist/worker-testing/stub-pi-tree-handle.d.ts +2 -0
  44. package/dist/worker-testing/stub-pi-tree-handle.d.ts.map +1 -1
  45. package/package.json +14 -9
  46. package/src/extension-integration-harness.ts +1059 -0
  47. package/src/fixtures.ts +16 -0
  48. package/src/index.ts +4 -19
  49. package/src/integration.ts +21 -0
  50. package/src/local-git.ts +1 -0
  51. package/src/observations.ts +19 -0
  52. package/src/process-fixtures.ts +123 -0
  53. package/src/process.ts +768 -0
  54. package/src/supported-question-fixtures.ts +168 -0
  55. package/src/test-capability.ts +9 -0
  56. package/src/worker-testing/in-process-worker-spawn.ts +15 -2
  57. package/src/worker-testing/stub-pi-tree-handle.ts +5 -0
  58. package/dist/chunk-2PCDTYVH.js.map +0 -1
  59. package/dist/chunk-ECAWLVYB.js.map +0 -1
package/src/fixtures.ts CHANGED
@@ -1,2 +1,18 @@
1
1
  export { createCompactProcessDetailFixtureFactory } from "./compact-process-detail-fixture.js";
2
+ export {
3
+ createProcessFixture,
4
+ createProjectFixture,
5
+ type ProcessFixtureOptions,
6
+ type ProcessFixturePosition,
7
+ type ProjectFixtureOptions,
8
+ } from "./process-fixtures.js";
2
9
  export { createTestQuestion, createTestQuestionRequest } from "./question-fixtures.js";
10
+ export {
11
+ createQuestionFixture,
12
+ createQuestionRequestFixture,
13
+ type QuestionFixture,
14
+ type QuestionFixtureOptions,
15
+ type QuestionFixtureResolution,
16
+ type QuestionRequestFixture,
17
+ type QuestionRequestFixtureOptions,
18
+ } from "./supported-question-fixtures.js";
package/src/index.ts CHANGED
@@ -11,25 +11,10 @@ export {
11
11
  createTestServerSetupCapability,
12
12
  createToolCollector,
13
13
  } from "./server-extension-test-harness.js";
14
+
14
15
  /** @internal */
15
- export function createInMemoryExternalWriteLog(): {
16
- /** @internal */
17
- records: Array<{
18
- /** @internal */
19
- dedupKey: string;
20
- }>;
21
- /** @internal */
22
- hasDedupKey(key: string): boolean;
23
- /** @internal */
24
- record(input: {
25
- /** @internal */
26
- dedupKey: string;
27
- }): {
28
- /** @internal */
29
- dedupKey: string;
30
- };
31
- /** @internal */
32
- getDedupKeys(): ReadonlySet<string>;
33
- } {
16
+ export function createInMemoryExternalWriteLog(): ReturnType<
17
+ typeof createInMemoryExternalWriteLogImpl
18
+ > {
34
19
  return createInMemoryExternalWriteLogImpl();
35
20
  }
@@ -1,3 +1,24 @@
1
+ export {
2
+ type AcceptedTurnFixture,
3
+ type AcceptedTurnReference,
4
+ createExtensionIntegrationHarness,
5
+ type ExtensionIntegrationHarness,
6
+ type ExtensionIntegrationHarnessOptions,
7
+ type ExtensionIntegrationProcess,
8
+ type ExtensionIntegrationSnapshot,
9
+ type ExtensionTestRequest,
10
+ type ExtensionTestResponse,
11
+ type IntegrationAnnotationObservation,
12
+ type IntegrationApprovalObservation,
13
+ type IntegrationEventObservation,
14
+ type IntegrationInputObservation,
15
+ type IntegrationLeafObservation,
16
+ type IntegrationProcessInput,
17
+ type IntegrationPromptObservation,
18
+ type IntegrationToolCall,
19
+ type IntegrationTurnResult,
20
+ type IntegrationTurnScript,
21
+ } from "./extension-integration-harness.js";
1
22
  export {
2
23
  createIntegrationHarness,
3
24
  createPersistentIntegrationFixture,
package/src/local-git.ts CHANGED
@@ -12,6 +12,7 @@ import path from "node:path";
12
12
  import type { RepositoryFeedbackItem, RepositoryPullRequest } from "@leitwerk-dev/process-sdk";
13
13
  import { traceTestSubprocess } from "./test-diagnostics.js";
14
14
 
15
+ // Internal operational tests retain subprocess diagnostics.
15
16
  export { createTestDiagnostics } from "./test-diagnostics.js";
16
17
 
17
18
  /** @public */
@@ -0,0 +1,19 @@
1
+ /** Recursively readonly observations detached from the running harness. @public */
2
+ export type TestObservation<T> = T extends readonly (infer V)[]
3
+ ? readonly TestObservation<V>[]
4
+ : T extends object
5
+ ? { readonly [K in keyof T]: TestObservation<T[K]> }
6
+ : T;
7
+
8
+ /** @internal */
9
+ export function observe<T>(value: T): TestObservation<T> {
10
+ function freeze(value: unknown): void {
11
+ if (value && typeof value === "object") {
12
+ for (const child of Object.values(value)) freeze(child);
13
+ Object.freeze(value);
14
+ }
15
+ }
16
+ const detached = structuredClone(value);
17
+ freeze(detached);
18
+ return detached as TestObservation<T>;
19
+ }
@@ -0,0 +1,123 @@
1
+ import type { ProcessInstance, ProcessProject } from "@leitwerk-dev/domain";
2
+ import {
3
+ createTestProcessInstance,
4
+ createTestProcessProject,
5
+ } from "@leitwerk-dev/extension-runtime/testing";
6
+ import type { ExtensionProcessDefinition } from "@leitwerk-dev/process-sdk";
7
+
8
+ /** Business position for an unaccepted fixture. @public */
9
+ export interface ProcessFixturePosition {
10
+ /** @public */
11
+ selectedTurnId: string | null;
12
+ /** @public */
13
+ lifecycleStatus: ProcessInstance["lifecycleStatus"];
14
+ }
15
+
16
+ /** Inputs deliberately exclude execution and acceptance records. @public */
17
+ export interface ProcessFixtureOptions<TParams = unknown, TState = unknown> {
18
+ /** @public */
19
+ id?: string;
20
+ /** @public */
21
+ processId?: string;
22
+ /** @public */
23
+ params?: TParams;
24
+ /** @public */
25
+ state?: TState;
26
+ /** @public */
27
+ position?: ProcessFixturePosition;
28
+ /** @public */
29
+ title?: string | null;
30
+ /** @public */
31
+ externalId?: string | null;
32
+ /** @public */
33
+ externalUrl?: string | null;
34
+ /** @public */
35
+ metadata?: Record<string, unknown> | null;
36
+ /** @public */
37
+ planRevision?: number;
38
+ }
39
+
40
+ /** Construct deterministic business data, validating codecs and turns when defined. @public */
41
+ export function createProcessFixture<TParams = unknown, TState = unknown>(
42
+ options: ProcessFixtureOptions<TParams, TState> = {},
43
+ definition?: ExtensionProcessDefinition<TParams, TState>,
44
+ ): ProcessInstance {
45
+ if (
46
+ options.planRevision !== undefined &&
47
+ (!Number.isSafeInteger(options.planRevision) || options.planRevision < 0)
48
+ )
49
+ throw new Error("planRevision must be a non-negative safe integer");
50
+ if (definition && options.processId && options.processId !== definition.id) {
51
+ throw new Error("Fixture process id does not match definition");
52
+ }
53
+ const params = definition ? definition.paramsCodec.parse(options.params) : options.params;
54
+ const state = definition
55
+ ? definition.stateCodec.parse(
56
+ options.state === undefined ? definition.initialState(params as TParams) : options.state,
57
+ )
58
+ : options.state;
59
+ const position = options.position ?? {
60
+ selectedTurnId: definition?.entryTurnId ?? null,
61
+ lifecycleStatus: definition ? "active" : "discovered",
62
+ };
63
+ if (
64
+ definition &&
65
+ position.selectedTurnId !== null &&
66
+ !definition.turns.has(position.selectedTurnId)
67
+ ) {
68
+ throw new Error(`Undeclared fixture turn '${position.selectedTurnId}'`);
69
+ }
70
+ return createTestProcessInstance({
71
+ id: options.id ?? "agt_test",
72
+ processId: definition?.id ?? options.processId ?? "test_process",
73
+ title: options.title ?? null,
74
+ externalId: options.externalId ?? null,
75
+ externalUrl: options.externalUrl ?? null,
76
+ metadata: structuredClone(options.metadata ?? null),
77
+ planRevision: options.planRevision ?? 0,
78
+ selectedTurnId: position.selectedTurnId,
79
+ lifecycleStatus: position.lifecycleStatus,
80
+ paramsJson:
81
+ params === undefined
82
+ ? null
83
+ : JSON.stringify(definition ? definition.paramsCodec.serialize(params as TParams) : params),
84
+ stateJson:
85
+ state === undefined
86
+ ? null
87
+ : JSON.stringify(definition ? definition.stateCodec.serialize(state as TState) : state),
88
+ });
89
+ }
90
+
91
+ /** Repository business data; ownership comes from the supplied process. @public */
92
+ export interface ProjectFixtureOptions {
93
+ /** Provider-owned repository bindings. @public */
94
+ metadata?: Record<string, unknown> | null;
95
+ /** @public */
96
+ id?: string;
97
+ /** @public */
98
+ process?: Pick<ProcessInstance, "id">;
99
+ /** @public */
100
+ key?: string;
101
+ /** @public */
102
+ repoLocator?: string;
103
+ /** @public */
104
+ repoLocatorKind?: ProcessProject["repoLocatorKind"];
105
+ /** @public */
106
+ baseBranch?: string;
107
+ /** @public */
108
+ workBranch?: string | null;
109
+ }
110
+
111
+ /** Construct a deterministic repository fixture correlated with its process. @public */
112
+ export function createProjectFixture(options: ProjectFixtureOptions = {}): ProcessProject {
113
+ return createTestProcessProject({
114
+ id: options.id ?? `prj_${options.key ?? "test"}`,
115
+ metadata: structuredClone(options.metadata ?? null),
116
+ instanceId: options.process?.id ?? "agt_test",
117
+ key: options.key ?? "component-a",
118
+ repoLocator: options.repoLocator ?? "https://example.invalid/component-a.git",
119
+ repoLocatorKind: options.repoLocatorKind ?? "remote_url",
120
+ baseBranch: options.baseBranch ?? "main",
121
+ workBranch: options.workBranch ?? null,
122
+ });
123
+ }