poe-code 10.0.0 → 10.0.2

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.
@@ -52,8 +52,18 @@ export function run(source, options = {}) {
52
52
  let leaveHostReplay;
53
53
  let leaveInputReplay;
54
54
  let createFailureSnapshot;
55
- let lastCheckpoint;
55
+ let cancellationSnapshot;
56
+ let cancellationSnapshotError;
56
57
  let snapshotScheduler;
58
+ const captureCancellationSnapshot = () => {
59
+ try {
60
+ cancellationSnapshot = createFailureSnapshot?.();
61
+ }
62
+ catch (reason) {
63
+ cancellationSnapshotError = { reason };
64
+ }
65
+ };
66
+ options.signal?.addEventListener("abort", captureCancellationSnapshot, { once: true });
57
67
  try {
58
68
  const restoredSnapshot = options.snapshot === undefined ? undefined : restore(options.snapshot, { source });
59
69
  if (restoredSnapshot !== undefined) {
@@ -165,6 +175,9 @@ export function run(source, options = {}) {
165
175
  bindings: executionScope.snapshot().bindings,
166
176
  clock: options.clock,
167
177
  hostCalls: hostCalls.snapshot(),
178
+ replay: hostCalls.snapshotReplay(),
179
+ initialInputs: initialInputs.snapshot,
180
+ promiseReplay: promiseReplay.snapshot(),
168
181
  random,
169
182
  sourceHash
170
183
  });
@@ -196,7 +209,6 @@ export function run(source, options = {}) {
196
209
  randomResumeState: typeof yieldPoint.replayState === "number" ? yieldPoint.replayState : undefined,
197
210
  sourceHash
198
211
  });
199
- lastCheckpoint = snapshot;
200
212
  return snapshot;
201
213
  };
202
214
  activeSnapshotScheduler.onYield(createSnapshot);
@@ -242,7 +254,6 @@ export function run(source, options = {}) {
242
254
  : undefined,
243
255
  sourceHash
244
256
  });
245
- lastCheckpoint = snapshot;
246
257
  return snapshot;
247
258
  };
248
259
  activeSnapshotScheduler.onYield(createSnapshot);
@@ -288,9 +299,11 @@ export function run(source, options = {}) {
288
299
  materializeWrappedErrorCause(error);
289
300
  if (createFailureSnapshot !== undefined && snapshotScheduler !== undefined) {
290
301
  try {
291
- const snapshot = lastCheckpoint ?? createFailureSnapshot();
292
- await snapshotScheduler.write(snapshot);
302
+ if (cancellationSnapshotError !== undefined)
303
+ throw cancellationSnapshotError.reason;
304
+ const snapshot = cancellationSnapshot ?? createFailureSnapshot();
293
305
  dumpController.finalize(snapshot);
306
+ await snapshotScheduler.write(snapshot);
294
307
  }
295
308
  catch (snapshotError) {
296
309
  if (snapshotError instanceof UnsnapshotableValueError) {
@@ -305,6 +318,7 @@ export function run(source, options = {}) {
305
318
  throw error;
306
319
  }
307
320
  finally {
321
+ options.signal?.removeEventListener("abort", captureCancellationSnapshot);
308
322
  leaveInputReplay?.();
309
323
  leaveHostReplay?.();
310
324
  promiseReplay.dispose();
@@ -1,7 +1,7 @@
1
1
  import { type Diagnostic } from "../lint.js";
2
2
  import type { ModuleRegistry } from "../modules/registry.js";
3
3
  import type { OtelSink } from "../observability/otel.js";
4
- import { type RunResult } from "../run.js";
4
+ import { type RunOptions, type RunResult } from "../run.js";
5
5
  import type { SnapshotBackend } from "../snapshot/backend.js";
6
6
  type HarnessMeta = {
7
7
  filepath: string;
@@ -9,6 +9,7 @@ type HarnessMeta = {
9
9
  version: unknown;
10
10
  };
11
11
  export type RunHarnessOptions = {
12
+ budget?: RunOptions["budget"];
12
13
  modulesFor: (frontmatter: Record<string, unknown>, meta: HarnessMeta) => ModuleRegistry;
13
14
  otelSink?: OtelSink;
14
15
  signal?: AbortSignal;
@@ -66,6 +66,7 @@ export async function runHarness(filepath, options) {
66
66
  throw new LintError(lintErrors);
67
67
  }
68
68
  return runHarnessSource(executableSource, {
69
+ budget: options.budget,
69
70
  entryPointArgs: hasDefaultExport(executableSource, filepath) ? [] : undefined,
70
71
  filename: filepath,
71
72
  modules,
@@ -102,6 +103,7 @@ export async function runHarnessPair(filepath, options) {
102
103
  throw new LintError(lintErrors);
103
104
  }
104
105
  return runHarnessSource(executableSource, {
106
+ budget: options.budget,
105
107
  entryPointArgs: [frontmatter],
106
108
  filename: pair.scriptPath,
107
109
  importMeta: {
@@ -1,17 +1,20 @@
1
1
  import type { RunResult, RunSnapshot } from "../run.js";
2
+ export type DumpOptions = {
3
+ onFailure?: "throw" | "checkpoint";
4
+ };
2
5
  type DumpController = {
3
6
  fail(error: unknown): void;
4
7
  finalize(snapshot: RunSnapshot): void;
5
8
  onYield(createSnapshot: () => RunSnapshot): void;
6
9
  requestCurrentSnapshot(): Promise<string>;
7
- requestSnapshot(): Promise<string>;
10
+ requestSnapshot(options?: DumpOptions): Promise<string>;
8
11
  };
9
12
  export type RunLifecycle = {
10
13
  hostCallbackDepth: number;
11
14
  };
12
15
  export declare function attachDumpController(result: Promise<RunResult>, controller: DumpController): Promise<RunResult>;
13
16
  export declare function createDumpController(lifecycle?: RunLifecycle): DumpController;
14
- export declare function dump(result: Pick<RunResult, "snapshot"> | PromiseLike<RunResult>): Promise<string>;
17
+ export declare function dump(result: Pick<RunResult, "snapshot"> | PromiseLike<RunResult>, options?: DumpOptions): Promise<string>;
15
18
  export declare function dumpCurrent(result: Pick<RunResult, "snapshot"> | PromiseLike<RunResult>): Promise<string>;
16
19
  export declare function serializeRunSnapshot(snapshot: RunSnapshot): string;
17
20
  export {};
@@ -61,13 +61,14 @@ export function createDumpController(lifecycle) {
61
61
  }
62
62
  return this.requestSnapshot();
63
63
  },
64
- requestSnapshot() {
64
+ requestSnapshot(options = {}) {
65
65
  assertDumpAllowed();
66
66
  if (failed !== undefined) {
67
- if (isDataBudgetError(failed.error) &&
68
- (latestSnapshot !== undefined || latestSnapshotFactory !== undefined)) {
67
+ if ((options.onFailure === "checkpoint" ||
68
+ (options.onFailure === undefined && isDataBudgetError(failed.error))) &&
69
+ finalSnapshot !== undefined) {
69
70
  try {
70
- return Promise.resolve(serializeRunSnapshot(latestSnapshot ?? latestSnapshotFactory()));
71
+ return Promise.resolve(serializeRunSnapshot(finalSnapshot));
71
72
  }
72
73
  catch (error) {
73
74
  return Promise.reject(error);
@@ -134,10 +135,10 @@ function isDataBudgetError(error) {
134
135
  "budget" in error &&
135
136
  error.budget === "dataSize");
136
137
  }
137
- export function dump(result) {
138
+ export function dump(result, options = {}) {
138
139
  const controller = readDumpController(result);
139
140
  if (controller !== undefined) {
140
- return controller.requestSnapshot();
141
+ return controller.requestSnapshot(options);
141
142
  }
142
143
  if (hasSnapshot(result)) {
143
144
  try {