From 28ddd330526a52572d9089af76fa648e40c4df39 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Fri, 26 Jan 2024 17:37:38 -0500 Subject: [PATCH 01/27] initial work --- libs/wingsdk/src/shared/sandbox.ts | 142 +++++++++++++++--- libs/wingsdk/src/shared/stream-processor.ts | 41 +++++ .../src/target-sim/function.inflight.ts | 4 +- .../src/target-sim/service.inflight.ts | 6 +- .../__snapshots__/simulator.test.ts.snap | 6 +- .../__snapshots__/function.test.ts.snap | 11 ++ .../__snapshots__/topic.test.ts.snap | 3 +- libs/wingsdk/test/target-sim/function.test.ts | 13 +- .../test/target-sim/stream-processor.test.ts | 60 ++++++++ libs/wingsdk/test/util.ts | 3 + 10 files changed, 248 insertions(+), 41 deletions(-) create mode 100644 libs/wingsdk/src/shared/stream-processor.ts create mode 100644 libs/wingsdk/test/target-sim/stream-processor.test.ts diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index d3cc868f980..792f270b92d 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -1,9 +1,11 @@ -import { mkdtemp, readFile } from "fs/promises"; +import * as cp from "child_process"; +import { mkdtemp, readFile, writeFile, stat } from "fs/promises"; import { tmpdir } from "os"; import * as path from "path"; import * as util from "util"; import * as vm from "vm"; import { createBundle } from "./bundling"; +import { processStream } from "./stream-processor"; export interface SandboxOptions { readonly env?: { [key: string]: string }; @@ -12,8 +14,119 @@ export interface SandboxOptions { readonly log?: (internal: boolean, level: string, message: string) => void; } +type ProcessRequest = { + fn: string; + args: any[]; +}; + +type ProcessResponse = + | { + type: "resolve"; + value: any; + } + | { + type: "reject"; + reason: Error; + }; + export class Sandbox { - private loaded = false; // "true" after first run (module is loaded into context) + private createBundlePromise: Promise; + private entrypoint: string; + private readonly options: SandboxOptions; + + constructor(entrypoint: string, options: SandboxOptions = {}) { + this.entrypoint = entrypoint; + this.options = options; + this.createBundlePromise = this.createBundle(); + } + + private async createBundle() { + const workdir = await mkdtemp(path.join(tmpdir(), "wing-bundles-")); + + // wrap contents with a shim that handles the communication with the parent process + // we insert this shim before bundling to ensure source maps will work correctly + let contents = (await readFile(this.entrypoint)).toString(); + + // log a warning if contents includes __dirname or __filename + if (contents.includes("__dirname") || contents.includes("__filename")) { + this.options.log?.( + false, + "warn", + `Warning: __dirname and __filename cannot be used within bundled cloud functions. There may be unexpected behavior.` + ); + } + + contents = ` +"use strict"; +${contents} +process.on("message", async (message) => { + const { fn, args } = message; + try { + const value = await exports[fn](...args); + process.send({ type: "resolve", value }); + } catch (err) { + process.send({ type: "reject", reason: err }); + } +}); +`; + const wrappedPath = this.entrypoint.replace(/\.js$/, ".sandbox.js"); + await writeFile(wrappedPath, contents); + const bundle = createBundle(wrappedPath, [], workdir); + this.entrypoint = bundle.entrypointPath; + + if (process.env.DEBUG) { + const bundleSize = (await stat(bundle.entrypointPath)).size; + this.options.log?.(true, "log", `Bundled code (${bundleSize} bytes).`); + } + } + + public async call(fn: string, ...args: any[]): Promise { + // wait for the bundle to finish creation + await this.createBundlePromise; + + // start a Node.js process that runs the bundled code + const child = cp.fork(this.entrypoint, [], { + env: this.options.env, + stdio: "pipe", + execArgv: ["--enable-source-maps"], + serialization: "advanced", + }); + + const log = (message: string) => this.options.log?.(false, "log", message); + const logError = (message: string) => + this.options.log?.(false, "error", message); + + if (child.stdout) { + processStream(child.stdout, log); + } + if (child.stderr) { + processStream(child.stderr, logError); + } + + return new Promise((resolve, reject) => { + child.send({ fn, args } as ProcessRequest); + child.on("message", (message: ProcessResponse) => { + if (message.type === "resolve") { + child.kill(); + resolve(message.value); + } else if (message.type === "reject") { + child.kill(); + reject(message.reason); + } + }); + child.on("error", (error) => { + child.kill(); + reject(error); + }); + child.on("exit", (code, _signal) => { + child.kill(); + reject(new Error(`Process exited with code ${code}`)); + }); + }); + } +} + +export class LegacySandbox { private createBundlePromise: Promise; private entrypoint: string; private code: string | undefined; @@ -109,10 +222,9 @@ export class Sandbox { } } - private loadBundleOnce() { - if (this.loaded) { - return; - } + public async call(fn: string, ...args: any[]): Promise { + // wait for the bundle to finish creation + await this.createBundlePromise; if (!this.code) { throw new Error("Bundle not created yet - please report this as a bug"); @@ -123,18 +235,6 @@ export class Sandbox { filename: this.entrypoint, }); - this.loaded = true; - } - - public async call(fn: string, ...args: any[]): Promise { - // wait for the bundle to finish creation - await this.createBundlePromise; - - // load the bundle into context on the first run - // we don't do this earlier because bundled code may have side effects - // and we want to simulate that a function is "cold" on the first run - this.loadBundleOnce(); - return new Promise(($resolve, $reject) => { const cleanup = () => { delete this.context.$resolve; @@ -151,9 +251,9 @@ export class Sandbox { $reject(reason); }; - const code = `exports.${fn}(${args.join( - "," - )}).then($resolve).catch($reject);`; + const code = `exports.${fn}(${args + .map((arg) => JSON.stringify(arg)) + .join(",")}).then($resolve).catch($reject);`; vm.runInContext(code, this.context, { filename: this.entrypoint, timeout: this.options.timeout, diff --git a/libs/wingsdk/src/shared/stream-processor.ts b/libs/wingsdk/src/shared/stream-processor.ts new file mode 100644 index 00000000000..6e7de668695 --- /dev/null +++ b/libs/wingsdk/src/shared/stream-processor.ts @@ -0,0 +1,41 @@ +import { Readable } from "stream"; +import { StringDecoder } from "string_decoder"; + +export function processStream( + stream: Readable, + callback: (message: string) => void +) { + let remainder = ""; + // StringDecoder to handle potentially incomplete multi-byte characters + const decoder = new StringDecoder(); + + stream.on("data", (data) => { + remainder = processStreamData(data, remainder, decoder, callback); + }); + + // Handle any remaining data when the streams are closed + stream.on("end", () => { + if (remainder) callback(remainder + decoder.end()); + }); + + stream.on("error", (error) => { + console.error(`Error occurred: ${error.message}`); + }); +} + +function processStreamData( + data: Buffer, + remainder: string, + decoder: StringDecoder, + log: (message: string) => void +): string { + let str = decoder.write(data); + let lines = (remainder + str).split("\n"); + + // Process all lines except the last one, which might be incomplete + for (let i = 0; i < lines.length - 1; i++) { + log(lines[i]); + } + + return lines.pop() ?? ""; // Return the last (potentially incomplete) line +} diff --git a/libs/wingsdk/src/target-sim/function.inflight.ts b/libs/wingsdk/src/target-sim/function.inflight.ts index ccadc821abe..a0f1ad2586f 100644 --- a/libs/wingsdk/src/target-sim/function.inflight.ts +++ b/libs/wingsdk/src/target-sim/function.inflight.ts @@ -55,7 +55,7 @@ export class Function implements IFunctionClient, ISimulatorResourceInstance { return this.context.withTrace({ message: `Invoke (payload=${JSON.stringify(payload)}).`, activity: async () => { - return this.sandbox.call("handler", JSON.stringify(payload)) ?? ""; + return this.sandbox.call("handler", payload) ?? ""; }, }); } @@ -65,7 +65,7 @@ export class Function implements IFunctionClient, ISimulatorResourceInstance { message: `InvokeAsync (payload=${JSON.stringify(payload)}).`, activity: async () => { process.nextTick(() => { - void this.sandbox.call("handler", JSON.stringify(payload)); + void this.sandbox.call("handler", payload); }); }, }); diff --git a/libs/wingsdk/src/target-sim/service.inflight.ts b/libs/wingsdk/src/target-sim/service.inflight.ts index 3124ff0fe79..9c115c77412 100644 --- a/libs/wingsdk/src/target-sim/service.inflight.ts +++ b/libs/wingsdk/src/target-sim/service.inflight.ts @@ -5,7 +5,7 @@ import { IServiceStopHandlerClient, SERVICE_FQN, } from "../cloud"; -import { Sandbox } from "../shared/sandbox"; +import { LegacySandbox } from "../shared/sandbox"; import { ISimulatorContext, ISimulatorResourceInstance } from "../simulator"; import { TraceType } from "../std"; @@ -13,7 +13,7 @@ export class Service implements IServiceClient, ISimulatorResourceInstance { private readonly context: ISimulatorContext; private readonly entrypoint: string; private readonly autoStart: boolean; - private readonly sandbox: Sandbox; + private readonly sandbox: LegacySandbox; private running: boolean = false; private onStop?: IServiceStopHandlerClient; @@ -21,7 +21,7 @@ export class Service implements IServiceClient, ISimulatorResourceInstance { this.context = context; this.entrypoint = resolve(context.simdir, props.sourceCodeFile); this.autoStart = props.autoStart; - this.sandbox = new Sandbox(this.entrypoint, { + this.sandbox = new LegacySandbox(this.entrypoint, { env: { ...props.environmentVariables, WING_SIMULATOR_URL: this.context.serverUrl, diff --git a/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap b/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap index 1c01368dc89..092cf52dd72 100644 --- a/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap +++ b/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap @@ -95,11 +95,7 @@ exports[`run single test > test failure 1`] = ` - at Script.runInContext (node:vm:) - at Object.runInContext (node:vm:) - - at new Promise () - + at process.emit (node:events:) ", "pass": false, diff --git a/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap index 7745fcb335d..8e872b74477 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/function.test.ts.snap @@ -1,5 +1,16 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html +exports[`__dirname and __filename cannot be used within inflight code 1`] = ` +[ + "@winglang/sdk.cloud.Function created.", + "@winglang/sdk.cloud.Function created.", + "Warning: __dirname and __filename cannot be used within bundled cloud functions. There may be unexpected behavior.", + "Warning: __dirname and __filename cannot be used within bundled cloud functions. There may be unexpected behavior.", + "Invoke (payload=\\"\\").", + "Invoke (payload=\\"\\").", +] +`; + exports[`create a function 1`] = ` { ".wing/my_function_c85c4e0e.js": "\\"use strict\\"; diff --git a/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap index 9f66179424b..d0fcdcffff4 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/topic.test.ts.snap @@ -136,10 +136,10 @@ exports[`topic publishes messages as they are received 1`] = ` "Publish (message=Alpha).", "Sending message (message=Alpha, subscriber=sim-0).", "InvokeAsync (payload=\\"Alpha\\").", - "Received Alpha", "Publish (message=Beta).", "Sending message (message=Beta, subscriber=sim-0).", "InvokeAsync (payload=\\"Beta\\").", + "Received Alpha", "Received Beta", "@winglang/sdk.sim.EventMapping deleted.", "@winglang/sdk.cloud.Topic deleted.", @@ -157,7 +157,6 @@ exports[`topic publishes messages to multiple subscribers 1`] = ` "Publish (message=Alpha).", "Sending message (message=Alpha, subscriber=sim-0).", "InvokeAsync (payload=\\"Alpha\\").", - "Received Alpha", "Sending message (message=Alpha, subscriber=sim-3).", "InvokeAsync (payload=\\"Alpha\\").", "@winglang/sdk.sim.EventMapping deleted.", diff --git a/libs/wingsdk/test/target-sim/function.test.ts b/libs/wingsdk/test/target-sim/function.test.ts index edf3f474c5c..b32ac6a9e2e 100644 --- a/libs/wingsdk/test/target-sim/function.test.ts +++ b/libs/wingsdk/test/target-sim/function.test.ts @@ -189,13 +189,13 @@ test("invoke function with process.exit(1)", async () => { // WHEN const PAYLOAD = {}; await expect(client.invoke(JSON.stringify(PAYLOAD))).rejects.toThrow( - "process.exit() was called with exit code 1" + "Process exited with code 1" ); // THEN await s.stop(); expect(listMessages(s)).toMatchSnapshot(); expect(s.listTraces()[1].data.error).toMatchObject({ - message: "process.exit() was called with exit code 1", + message: "Process exited with code 1", }); expect(app.snapshot()).toMatchSnapshot(); }); @@ -243,11 +243,8 @@ test("__dirname and __filename cannot be used within inflight code", async () => const s = await app.startSimulator(); - await expect(dirnameInvoker(s)).rejects.toThrow( - "__dirname cannot be used within bundled cloud functions" - ); + await dirnameInvoker(s); + await filenameInvoker(s); - await expect(filenameInvoker(s)).rejects.toThrow( - "__filename cannot be used within bundled cloud functions" - ); + expect(listMessages(s)).toMatchSnapshot(); }); diff --git a/libs/wingsdk/test/target-sim/stream-processor.test.ts b/libs/wingsdk/test/target-sim/stream-processor.test.ts new file mode 100644 index 00000000000..de19ce606a4 --- /dev/null +++ b/libs/wingsdk/test/target-sim/stream-processor.test.ts @@ -0,0 +1,60 @@ +import { Readable } from "stream"; +import { describe, expect, it, vi } from "vitest"; +import { processStream } from "../../src/shared/stream-processor"; + +describe("processStream", () => { + it("should process data events correctly", () => + new Promise((done) => { + const mockData = Buffer.from("Hello\nWorld\n"); + const mockStream = new Readable(); + mockStream.push(mockData); + mockStream.push(null); // Indicates end of stream + + const mockCallback = vi.fn(); + + processStream(mockStream, mockCallback); + + setImmediate(() => { + expect(mockCallback).toHaveBeenCalledTimes(2); + expect(mockCallback).toHaveBeenNthCalledWith(1, "Hello"); + expect(mockCallback).toHaveBeenNthCalledWith(2, "World"); + done(undefined); + }); + })); + + it("should process lines split among multiple chunks", () => + new Promise((done) => { + const mockData1 = Buffer.from("Hello "); + const mockData2 = Buffer.from("world\n"); + const mockStream = new Readable(); + mockStream.push(mockData1); + mockStream.push(mockData2); + mockStream.push(null); // Indicates end of stream + + const mockCallback = vi.fn(); + + processStream(mockStream, mockCallback); + + setImmediate(() => { + expect(mockCallback).toHaveBeenCalledTimes(1); + expect(mockCallback).toHaveBeenNthCalledWith(1, "Hello world"); + done(undefined); + }); + })); + + it("should handle error events", () => + new Promise((done) => { + const mockStream = new Readable(); + const mockCallback = vi.fn(); + const consoleSpy = vi.spyOn(console, "error"); + + processStream(mockStream, mockCallback); + + mockStream.emit("error", new Error("Test error")); + + setImmediate(() => { + expect(consoleSpy).toHaveBeenCalledWith("Error occurred: Test error"); + done(undefined); + }); + })); +}); diff --git a/libs/wingsdk/test/util.ts b/libs/wingsdk/test/util.ts index a214f895bc6..eb211185981 100644 --- a/libs/wingsdk/test/util.ts +++ b/libs/wingsdk/test/util.ts @@ -149,6 +149,9 @@ export function directorySnapshot(initialRoot: string) { break; case ".js": + if (f.endsWith(".sandbox.js")) { + continue; + } const code = readFileSync(abspath, "utf-8"); snapshot[key] = sanitizeCode(code); break; From 2278460a14132113e7df2fde62249e377639cbe6 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Fri, 26 Jan 2024 17:50:53 -0500 Subject: [PATCH 02/27] update a test --- .../valid/inflight_handler_singleton.test.w | 28 ++++++++++++++----- .../function/invoke.test.w_test_sim.md | 4 +-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/examples/tests/valid/inflight_handler_singleton.test.w b/examples/tests/valid/inflight_handler_singleton.test.w index f9901e146d1..2a629213a53 100644 --- a/examples/tests/valid/inflight_handler_singleton.test.w +++ b/examples/tests/valid/inflight_handler_singleton.test.w @@ -12,6 +12,10 @@ class Foo { this.n += 1; return this.n; } + + pub inflight get(): num { + return this.n; + } } let foo = new Foo(); @@ -36,11 +40,21 @@ test "single instance of Foo" { expect.equal(x, "100"); expect.equal(z, "100-fn2"); // fn2 should have a separate instance - // the simulator intentionally reuses the sandbox across invocations - // but we can't trust that this will always happen on the cloud - if sim { - expect.equal(y, "101"); - expect.equal(z, "100-fn2"); // fn2 should have a separate instance - log("client has been reused"); - } + // y could be 100 or 101 depending on whether the execution environment + // was reused or not between the two calls. + assert(y == "100" || y == "101"); +} + +// a function that takes at least three seconds to run +let incAndCheck = new cloud.Function(inflight () => { + let n = foo.inc(); + util.sleep(3s); + assert(n == foo.get()); +}) as "incAndCheck"; + +test "Foo state is not shared between concurrent function invocations" { + // start two invocations of fn, staggering them by 1 second + incAndCheck.invokeAsync(""); + util.sleep(1s); + incAndCheck.invoke(""); } diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md index d815c824fb0..f78b422d944 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md @@ -5,8 +5,8 @@ log preflight pass ┌ invoke.test.wsim » root/env0/test:invoke │ log inside test - └ log inside function -contains 2 lines + │ log inside function + └ contains 2 lines Tests 1 passed (1) From bbc5830f24ac1e58dd55ff9e629805cc5cc93b1f Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Fri, 26 Jan 2024 18:10:38 -0500 Subject: [PATCH 03/27] fix timeouts, add extra tests --- .../tests/sdk_tests/function/timeout.test.w | 8 ++------ examples/tests/valid/deep_equality.test.w | 5 +++++ libs/wingsdk/src/shared/sandbox.ts | 19 +++++++++++++++++++ .../src/target-sim/function.inflight.ts | 2 +- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/examples/tests/sdk_tests/function/timeout.test.w b/examples/tests/sdk_tests/function/timeout.test.w index 7f4eb9c1c9d..8bf2df09b3e 100644 --- a/examples/tests/sdk_tests/function/timeout.test.w +++ b/examples/tests/sdk_tests/function/timeout.test.w @@ -35,9 +35,7 @@ new std.Test(inflight () => { assert(e.contains("Task timed out after")); } - if (util.env("WING_TARGET") != "sim") { - assert(c.peek() == 0); - } + assert(c.peek() == 0); try { f2.invoke(""); @@ -49,8 +47,6 @@ new std.Test(inflight () => { assert(e.contains("Task timed out after")); } - if (util.env("WING_TARGET") != "sim") { - assert(c.peek() == 1); - } + assert(c.peek() == 1); }, std.TestProps {timeout: 2m}) as "timeout"; diff --git a/examples/tests/valid/deep_equality.test.w b/examples/tests/valid/deep_equality.test.w index 36ad386055a..f5dc909e012 100644 --- a/examples/tests/valid/deep_equality.test.w +++ b/examples/tests/valid/deep_equality.test.w @@ -39,6 +39,11 @@ test "Json with different values" { assert(!(jsonA != jsonB)); } +test "Json.values equality" { + let j = Json { hello: 123, world: [1, 2, 3] }; + assert(Json.values(j) == [Json 123, Json [1, 2, 3]]); +} + //----------------------------------------------------------------------------- // Set //----------------------------------------------------------------------------- diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index 792f270b92d..5811e2a4cbb 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -32,6 +32,7 @@ type ProcessResponse = export class Sandbox { private createBundlePromise: Promise; private entrypoint: string; + private readonly timeouts: NodeJS.Timeout[] = []; private readonly options: SandboxOptions; constructor(entrypoint: string, options: SandboxOptions = {}) { @@ -40,6 +41,12 @@ export class Sandbox { this.createBundlePromise = this.createBundle(); } + public async cleanup() { + for (const timeout of this.timeouts) { + clearTimeout(timeout); + } + } + private async createBundle() { const workdir = await mkdtemp(path.join(tmpdir(), "wing-bundles-")); @@ -122,6 +129,18 @@ process.on("message", async (message) => { child.kill(); reject(new Error(`Process exited with code ${code}`)); }); + + if (this.options.timeout) { + const timeout = setTimeout(() => { + child.kill(); + reject( + new Error( + `Function timed out (it was configured to only run for ${this.options.timeout}ms)` + ) + ); + }, this.options.timeout); + this.timeouts.push(timeout); + } }); } } diff --git a/libs/wingsdk/src/target-sim/function.inflight.ts b/libs/wingsdk/src/target-sim/function.inflight.ts index a0f1ad2586f..7c13185b985 100644 --- a/libs/wingsdk/src/target-sim/function.inflight.ts +++ b/libs/wingsdk/src/target-sim/function.inflight.ts @@ -46,7 +46,7 @@ export class Function implements IFunctionClient, ISimulatorResourceInstance { } public async cleanup(): Promise { - return; + await this.sandbox.cleanup(); } public async save(): Promise {} From 89fa7cc8723ea447677d36e14a9c919c092d4c89 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 14:46:58 -0500 Subject: [PATCH 04/27] update test --- examples/tests/valid/inflight_handler_singleton.test.w | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/tests/valid/inflight_handler_singleton.test.w b/examples/tests/valid/inflight_handler_singleton.test.w index 2a629213a53..8d0520ab72e 100644 --- a/examples/tests/valid/inflight_handler_singleton.test.w +++ b/examples/tests/valid/inflight_handler_singleton.test.w @@ -54,7 +54,7 @@ let incAndCheck = new cloud.Function(inflight () => { test "Foo state is not shared between concurrent function invocations" { // start two invocations of fn, staggering them by 1 second - incAndCheck.invokeAsync(""); + incAndCheck.invokeAsync(); util.sleep(1s); - incAndCheck.invoke(""); + incAndCheck.invoke(); } From 4f0c38103b0e79fc09448b2d918d616f32a85f2b Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 15:07:43 -0500 Subject: [PATCH 05/27] fix comments --- libs/wingsdk/src/shared/sandbox.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index 5811e2a4cbb..5eac525a2cf 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -51,7 +51,7 @@ export class Sandbox { const workdir = await mkdtemp(path.join(tmpdir(), "wing-bundles-")); // wrap contents with a shim that handles the communication with the parent process - // we insert this shim before bundling to ensure source maps will work correctly + // we insert this shim before bundling to ensure source maps are generated correctly let contents = (await readFile(this.entrypoint)).toString(); // log a warning if contents includes __dirname or __filename @@ -103,6 +103,7 @@ process.on("message", async (message) => { const logError = (message: string) => this.options.log?.(false, "error", message); + // pipe stdout and stderr from the child process if (child.stdout) { processStream(child.stdout, log); } From 12a018d1f89dc474800ae4ede7de3e69ed990cdf Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 15:08:21 -0500 Subject: [PATCH 06/27] try maxConcurrency to see if that makes tests more stable --- libs/wingsdk/vitest.config.mts | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/wingsdk/vitest.config.mts b/libs/wingsdk/vitest.config.mts index 1cb7948faf8..58a4ab05700 100644 --- a/libs/wingsdk/vitest.config.mts +++ b/libs/wingsdk/vitest.config.mts @@ -8,5 +8,6 @@ export default defineConfig({ // https://vitest.dev/guide/features.html#chai-and-jest-expect-compatibility // Allows to use the matchers added by "aws-sdk-client-mock-jest" globals: true, + maxConcurrency: 1, }, }); From e90038aae05759181be90c197d55ce5398cdaf0f Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 15:18:56 -0500 Subject: [PATCH 07/27] nah there's still a problem --- libs/wingsdk/vitest.config.mts | 1 - 1 file changed, 1 deletion(-) diff --git a/libs/wingsdk/vitest.config.mts b/libs/wingsdk/vitest.config.mts index 58a4ab05700..1cb7948faf8 100644 --- a/libs/wingsdk/vitest.config.mts +++ b/libs/wingsdk/vitest.config.mts @@ -8,6 +8,5 @@ export default defineConfig({ // https://vitest.dev/guide/features.html#chai-and-jest-expect-compatibility // Allows to use the matchers added by "aws-sdk-client-mock-jest" globals: true, - maxConcurrency: 1, }, }); From 5f1e2b5869f79e3cf3e44f10d7f24c80e94fea0e Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Tue, 5 Mar 2024 20:29:34 +0000 Subject: [PATCH 08/27] chore: self mutation (build.diff) Signed-off-by: monada-bot[bot] --- .../target-sim/__snapshots__/api.test.ts.snap | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap index f54c91bd11a..024e61fe721 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap @@ -278,7 +278,7 @@ exports[`api handler can read the request params 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -547,7 +547,7 @@ exports[`api handler can read the request path 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -816,7 +816,7 @@ exports[`api handler can set response headers 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1085,7 +1085,7 @@ exports[`api response returns Content-Type header from inflight 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1354,7 +1354,7 @@ exports[`api response returns default Content-Type header 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1623,25 +1623,25 @@ exports[`api supports every method type 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "Processing "PUT /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "PUT /hello - 200.", "Processing "DELETE /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "DELETE /hello - 200.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "OPTIONS /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "OPTIONS /hello - 200.", "Processing "PATCH /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "PATCH /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2024,7 +2024,7 @@ exports[`api with 'name' & 'age' parameter 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /:name/:age" params={"name":"akhil","age":"23"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil/23\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\",\\"age\\":\\"23\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil/23\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\",\\"age\\":\\"23\\"}}").", "GET /:name/:age - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2310,7 +2310,7 @@ exports[`api with 'name' parameter 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /:name" params={"name":"akhil"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\"}}").", "GET /:name - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2856,10 +2856,10 @@ exports[`api with multiple methods on same route 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "@winglang/sdk.cloud.Function deleted.", @@ -3219,10 +3219,10 @@ exports[`api with multiple routes 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello/world" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello/world - 200.", "Processing "GET /hello/wingnuts" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello/wingnuts - 200.", "@winglang/sdk.sim.EventMapping deleted.", "@winglang/sdk.cloud.Function deleted.", @@ -3582,7 +3582,7 @@ exports[`api with one GET route 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -3851,7 +3851,7 @@ exports[`api with one GET route with request params 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /users/:name" params={"name":"tsuf"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}").", "GET /users/:name - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -4129,7 +4129,7 @@ exports[`api with one POST route, with body 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"content-type\\":\\"application/json\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"25\\"},\\"body\\":\\"{\\\\\\"message\\\\\\":\\\\\\"hello world\\\\\\"}\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"content-type\\":\\"application/json\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"25\\"},\\"body\\":\\"{\\\\\\"message\\\\\\":\\\\\\"hello world\\\\\\"}\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", From 507ffa5ff00f0b728a2ed660423a7b5b2aca4c03 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 19:56:37 -0500 Subject: [PATCH 09/27] move legacy sandbox to separate file, tweak child process handling --- libs/wingsdk/src/shared/legacy-sandbox.ts | 143 ++++++++++++ libs/wingsdk/src/shared/sandbox.ts | 212 ++++++------------ .../src/target-sim/service.inflight.ts | 2 +- 3 files changed, 207 insertions(+), 150 deletions(-) create mode 100644 libs/wingsdk/src/shared/legacy-sandbox.ts diff --git a/libs/wingsdk/src/shared/legacy-sandbox.ts b/libs/wingsdk/src/shared/legacy-sandbox.ts new file mode 100644 index 00000000000..f7f3dcadaf8 --- /dev/null +++ b/libs/wingsdk/src/shared/legacy-sandbox.ts @@ -0,0 +1,143 @@ +import { mkdtemp, readFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import * as util from "node:util"; +import * as vm from "node:vm"; +import { createBundle } from "./bundling"; +import { SandboxOptions } from "./sandbox"; + +export class LegacySandbox { + private createBundlePromise: Promise; + private entrypoint: string; + private code: string | undefined; + private readonly options: SandboxOptions; + private readonly context: any = {}; + + constructor(entrypoint: string, options: SandboxOptions = {}) { + this.entrypoint = entrypoint; + this.options = options; + this.context = this.createContext(); + this.createBundlePromise = this.createBundle(); + } + + private createContext() { + const sandboxProcess = { + ...process, + + // override process.exit to throw an exception instead of exiting the process + exit: (exitCode: number) => { + throw new Error("process.exit() was called with exit code " + exitCode); + }, + + env: this.options.env, + }; + + const sandboxConsole: any = {}; + const levels = ["debug", "info", "log", "warn", "error"]; + for (const level of levels) { + sandboxConsole[level] = (...args: any[]) => { + const message = util.format(...args); + this.options.log?.(false, level, message); + // also log to stderr if DEBUG is set + if (process.env.DEBUG) { + console.error(message); + } + }; + } + + const ctx: any = {}; + + // create a copy of all the globals from our current context. + for (const k of Object.getOwnPropertyNames(global)) { + try { + ctx[k] = (global as any)[k]; + } catch { + // ignore unresolvable globals (see https://github.com/winglang/wing/pull/1923) + } + } + + // append the user's context + for (const [k, v] of Object.entries(this.options.context ?? {})) { + ctx[k] = v; + } + + const context = vm.createContext({ + ...ctx, + process: sandboxProcess, + console: sandboxConsole, + exports: {}, + require, // to support requiring node.js sdk modules (others will be bundled) + }); + + // emit an explicit error when trying to access `__dirname` and `__filename` because we cannot + // resolve these when bundling (this is true both for simulator and the cloud since we are + // bundling there as well). + const forbidGlobal = (name: string) => { + Object.defineProperty(context, name, { + get: () => { + throw new Error( + `${name} cannot be used within bundled cloud functions` + ); + }, + }); + }; + + forbidGlobal("__dirname"); + forbidGlobal("__filename"); + + return context; + } + + private async createBundle() { + // load bundle into context on first run + const workdir = await mkdtemp(path.join(tmpdir(), "wing-bundles-")); + const bundle = createBundle(this.entrypoint, [], workdir); + this.entrypoint = bundle.entrypointPath; + + this.code = await readFile(this.entrypoint, "utf-8"); + + if (process.env.DEBUG) { + const bundleSize = Buffer.byteLength(this.code, "utf-8"); + this.options.log?.(true, "log", `Bundled code (${bundleSize} bytes).`); + } + } + + public async call(fn: string, ...args: any[]): Promise { + // wait for the bundle to finish creation + await this.createBundlePromise; + + if (!this.code) { + throw new Error("Bundle not created yet - please report this as a bug"); + } + + // this will add stuff to the "exports" object within our context + vm.runInContext(this.code!, this.context, { + filename: this.entrypoint, + }); + + return new Promise(($resolve, $reject) => { + const cleanup = () => { + delete this.context.$resolve; + delete this.context.$reject; + }; + + this.context.$resolve = (value: any) => { + cleanup(); + $resolve(value); + }; + + this.context.$reject = (reason?: any) => { + cleanup(); + $reject(reason); + }; + + const code = `exports.${fn}(${args + .map((arg) => JSON.stringify(arg)) + .join(",")}).then($resolve).catch($reject);`; + vm.runInContext(code, this.context, { + filename: this.entrypoint, + timeout: this.options.timeout, + }); + }); + } +} diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index 5eac525a2cf..5f8c8d3e07e 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -1,9 +1,8 @@ import * as cp from "child_process"; -import { mkdtemp, readFile, writeFile, stat } from "fs/promises"; +import { writeFileSync } from "fs"; +import { mkdtemp, readFile, stat } from "fs/promises"; import { tmpdir } from "os"; import * as path from "path"; -import * as util from "util"; -import * as vm from "vm"; import { createBundle } from "./bundling"; import { processStream } from "./stream-processor"; @@ -32,6 +31,7 @@ type ProcessResponse = export class Sandbox { private createBundlePromise: Promise; private entrypoint: string; + private readonly exitingChildren: Promise[] = []; private readonly timeouts: NodeJS.Timeout[] = []; private readonly options: SandboxOptions; @@ -45,6 +45,12 @@ export class Sandbox { for (const timeout of this.timeouts) { clearTimeout(timeout); } + // It's possible that the sandbox's call() method was invoked without being awaited. + // If that's the case, we need to wait for the child process to exit before we can + // clean up the sandbox. + for (const child of this.exitingChildren) { + await child; + } } private async createBundle() { @@ -77,13 +83,13 @@ process.on("message", async (message) => { }); `; const wrappedPath = this.entrypoint.replace(/\.js$/, ".sandbox.js"); - await writeFile(wrappedPath, contents); + writeFileSync(wrappedPath, contents); // async fsPromises.writeFile "flush" option is not available in Node 20 const bundle = createBundle(wrappedPath, [], workdir); this.entrypoint = bundle.entrypointPath; if (process.env.DEBUG) { const bundleSize = (await stat(bundle.entrypointPath)).size; - this.options.log?.(true, "log", `Bundled code (${bundleSize} bytes).`); + this.debugLog(`Bundled code (${bundleSize} bytes).`); } } @@ -91,6 +97,8 @@ process.on("message", async (message) => { // wait for the bundle to finish creation await this.createBundlePromise; + this.debugLog("Forking process to run bundled code."); + // start a Node.js process that runs the bundled code const child = cp.fork(this.entrypoint, [], { env: this.options.env, @@ -111,173 +119,79 @@ process.on("message", async (message) => { processStream(child.stderr, logError); } + // Keep track of when the child process exits so that the simulator doesn't try + // to clean up the sandbox before the child process has exited. + // NOTE: If child processes are taking too long to exit (preventing simulator cleanups), + // we could add a mechanism to send SIGKILL to the child process after a certain amount of time. + let childExited: (value?: any) => void; + this.exitingChildren.push( + new Promise((resolve) => { + childExited = resolve; + }) + ); + + // Send the function name and arguments to the child process. + // When a message is received, kill the child process. + // Once the child process is killed (by the parent process or because the user code + // exited on its own), resolve or reject the promise. return new Promise((resolve, reject) => { child.send({ fn, args } as ProcessRequest); + + let result: any; + let status: "resolve" | "reject" | "pending" = "pending"; child.on("message", (message: ProcessResponse) => { + this.debugLog("Received a message, killing child process."); + child.kill(); if (message.type === "resolve") { - child.kill(); - resolve(message.value); + result = message.value; + status = "resolve"; } else if (message.type === "reject") { - child.kill(); - reject(message.reason); + result = message.reason; + status = "reject"; + } else { + result = `Parent received unexpected message from child process: ${message}`; + status = "reject"; } }); child.on("error", (error) => { - child.kill(); - reject(error); + this.debugLog("Killing process after error."); + // Something unexpected happened. "error" could be emitted for any number of reasons + // (the process couldn't be spawned or killed, or a message couldn't be sent), + // so we kill the process with SIGKILL to ensure it's dead, and reject the promise. + child.kill("SIGKILL"); + childExited(); + reject(`Unexpected error: ${error}`); }); child.on("exit", (code, _signal) => { - child.kill(); - reject(new Error(`Process exited with code ${code}`)); + this.debugLog("Child processed stopped."); + childExited(); + if (status === "pending") { + // If the child process stopped without sending us back a message, reject the promise. + reject(new Error(`Process exited with code ${code}`)); + } else if (status === "resolve") { + resolve(result); + } else if (status === "reject") { + reject(result); + } }); if (this.options.timeout) { const timeout = setTimeout(() => { + this.debugLog("Killing process after timeout."); child.kill(); - reject( - new Error( - `Function timed out (it was configured to only run for ${this.options.timeout}ms)` - ) + status = "reject"; + result = new Error( + `Function timed out (it was configured to only run for ${this.options.timeout}ms)` ); }, this.options.timeout); this.timeouts.push(timeout); } }); } -} - -export class LegacySandbox { - private createBundlePromise: Promise; - private entrypoint: string; - private code: string | undefined; - private readonly options: SandboxOptions; - private readonly context: any = {}; - - constructor(entrypoint: string, options: SandboxOptions = {}) { - this.entrypoint = entrypoint; - this.options = options; - this.context = this.createContext(); - this.createBundlePromise = this.createBundle(); - } - - private createContext() { - const sandboxProcess = { - ...process, - - // override process.exit to throw an exception instead of exiting the process - exit: (exitCode: number) => { - throw new Error("process.exit() was called with exit code " + exitCode); - }, - - env: this.options.env, - }; - - const sandboxConsole: any = {}; - const levels = ["debug", "info", "log", "warn", "error"]; - for (const level of levels) { - sandboxConsole[level] = (...args: any[]) => { - const message = util.format(...args); - this.options.log?.(false, level, message); - // also log to stderr if DEBUG is set - if (process.env.DEBUG) { - console.error(message); - } - }; - } - - const ctx: any = {}; - - // create a copy of all the globals from our current context. - for (const k of Object.getOwnPropertyNames(global)) { - try { - ctx[k] = (global as any)[k]; - } catch { - // ignore unresolvable globals (see https://github.com/winglang/wing/pull/1923) - } - } - - // append the user's context - for (const [k, v] of Object.entries(this.options.context ?? {})) { - ctx[k] = v; - } - - const context = vm.createContext({ - ...ctx, - process: sandboxProcess, - console: sandboxConsole, - exports: {}, - require, // to support requiring node.js sdk modules (others will be bundled) - }); - - // emit an explicit error when trying to access `__dirname` and `__filename` because we cannot - // resolve these when bundling (this is true both for simulator and the cloud since we are - // bundling there as well). - const forbidGlobal = (name: string) => { - Object.defineProperty(context, name, { - get: () => { - throw new Error( - `${name} cannot be used within bundled cloud functions` - ); - }, - }); - }; - - forbidGlobal("__dirname"); - forbidGlobal("__filename"); - - return context; - } - - private async createBundle() { - // load bundle into context on first run - const workdir = await mkdtemp(path.join(tmpdir(), "wing-bundles-")); - const bundle = createBundle(this.entrypoint, [], workdir); - this.entrypoint = bundle.entrypointPath; - - this.code = await readFile(this.entrypoint, "utf-8"); + private debugLog(message: string) { if (process.env.DEBUG) { - const bundleSize = Buffer.byteLength(this.code, "utf-8"); - this.options.log?.(true, "log", `Bundled code (${bundleSize} bytes).`); + this.options.log?.(true, "log", message); } } - - public async call(fn: string, ...args: any[]): Promise { - // wait for the bundle to finish creation - await this.createBundlePromise; - - if (!this.code) { - throw new Error("Bundle not created yet - please report this as a bug"); - } - - // this will add stuff to the "exports" object within our context - vm.runInContext(this.code!, this.context, { - filename: this.entrypoint, - }); - - return new Promise(($resolve, $reject) => { - const cleanup = () => { - delete this.context.$resolve; - delete this.context.$reject; - }; - - this.context.$resolve = (value: any) => { - cleanup(); - $resolve(value); - }; - - this.context.$reject = (reason?: any) => { - cleanup(); - $reject(reason); - }; - - const code = `exports.${fn}(${args - .map((arg) => JSON.stringify(arg)) - .join(",")}).then($resolve).catch($reject);`; - vm.runInContext(code, this.context, { - filename: this.entrypoint, - timeout: this.options.timeout, - }); - }); - } } diff --git a/libs/wingsdk/src/target-sim/service.inflight.ts b/libs/wingsdk/src/target-sim/service.inflight.ts index 9c115c77412..4795f6521b4 100644 --- a/libs/wingsdk/src/target-sim/service.inflight.ts +++ b/libs/wingsdk/src/target-sim/service.inflight.ts @@ -5,7 +5,7 @@ import { IServiceStopHandlerClient, SERVICE_FQN, } from "../cloud"; -import { LegacySandbox } from "../shared/sandbox"; +import { LegacySandbox } from "../shared/legacy-sandbox"; import { ISimulatorContext, ISimulatorResourceInstance } from "../simulator"; import { TraceType } from "../std"; From c68b82e9950236ec51e8e11172603b1cbc3733b6 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 19:58:53 -0500 Subject: [PATCH 10/27] adjust comment --- libs/wingsdk/src/shared/sandbox.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index 5f8c8d3e07e..e0e6d7c2c21 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -13,11 +13,17 @@ export interface SandboxOptions { readonly log?: (internal: boolean, level: string, message: string) => void; } +/** + * Shape of the messages sent to the child process. + */ type ProcessRequest = { fn: string; args: any[]; }; +/** + * Shape of the messages returned by the child process. + */ type ProcessResponse = | { type: "resolve"; @@ -45,9 +51,7 @@ export class Sandbox { for (const timeout of this.timeouts) { clearTimeout(timeout); } - // It's possible that the sandbox's call() method was invoked without being awaited. - // If that's the case, we need to wait for the child process to exit before we can - // clean up the sandbox. + // Make sure all child processes have exited before cleaning up the sandbox. for (const child of this.exitingChildren) { await child; } From ec3676acbddb1d16094d84755410587e6c4e35e6 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 20:05:40 -0500 Subject: [PATCH 11/27] cleanup, update tests --- libs/wingsdk/src/shared/sandbox.ts | 9 +- libs/wingsdk/src/shared/stream-processor.ts | 6 + tools/hangar/__snapshots__/error.ts.snap | 40 +--- .../function/invoke.test.w_test_sim.md | 4 +- .../deep_equality.test.w_compile_tf-aws.md | 179 ++++++++++----- .../valid/deep_equality.test.w_test_sim.md | 19 +- ...handler_singleton.test.w_compile_tf-aws.md | 217 +++++++++++++++++- ...light_handler_singleton.test.w_test_sim.md | 6 +- 8 files changed, 364 insertions(+), 116 deletions(-) diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index e0e6d7c2c21..b552344a4f8 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -143,6 +143,7 @@ process.on("message", async (message) => { let result: any; let status: "resolve" | "reject" | "pending" = "pending"; + child.on("message", (message: ProcessResponse) => { this.debugLog("Received a message, killing child process."); child.kill(); @@ -157,15 +158,17 @@ process.on("message", async (message) => { status = "reject"; } }); + + // Something unexpected happened. "error" could be emitted for any number of reasons + // (the process couldn't be spawned or killed, or a message couldn't be sent), + // so we kill the process with SIGKILL to ensure it's dead, and reject the promise. child.on("error", (error) => { this.debugLog("Killing process after error."); - // Something unexpected happened. "error" could be emitted for any number of reasons - // (the process couldn't be spawned or killed, or a message couldn't be sent), - // so we kill the process with SIGKILL to ensure it's dead, and reject the promise. child.kill("SIGKILL"); childExited(); reject(`Unexpected error: ${error}`); }); + child.on("exit", (code, _signal) => { this.debugLog("Child processed stopped."); childExited(); diff --git a/libs/wingsdk/src/shared/stream-processor.ts b/libs/wingsdk/src/shared/stream-processor.ts index 6e7de668695..d65c34096d5 100644 --- a/libs/wingsdk/src/shared/stream-processor.ts +++ b/libs/wingsdk/src/shared/stream-processor.ts @@ -1,6 +1,12 @@ import { Readable } from "stream"; import { StringDecoder } from "string_decoder"; +/** + * Processes a stream, invoking a callback function for each line of data. + * + * @param stream - The readable stream to process. + * @param callback - The function to invoke for each line of data. + */ export function processStream( stream: Readable, callback: (message: string) => void diff --git a/tools/hangar/__snapshots__/error.ts.snap b/tools/hangar/__snapshots__/error.ts.snap index 8ffaed3182b..a7fec3095c0 100644 --- a/tools/hangar/__snapshots__/error.ts.snap +++ b/tools/hangar/__snapshots__/error.ts.snap @@ -20,44 +20,28 @@ Duration " exports[`inflight_stacktraces.test.w 1`] = ` "fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert │ Error: assertion failed: false - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:7:3 - │ | let bucket = new cloud.Bucket(); - │ | - │ | test \\"assert\\" { - │ 7 | assert(false); - │ | ^ - └ at /inflight_stacktraces.test.w:7:3 + │ at /inflight_stacktraces.test.w:7:3 + │ at handler /handler_c8b175d2.sandbox.js:18:25 + └ at /handler_c8b175d2.sandbox.js:23:19 fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ Error: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: │ │ 1 !== 2 │ - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:11:3 - │ | } - │ | - │ | test \\"expect.equal\\" { - │ 11 | expect.equal(1,2 ); - │ | ^ - └ at /inflight_stacktraces.test.w:11:3 + │ at /inflight_stacktraces.test.w:11:3 + │ at handler /handler_c822920b.sandbox.js:19:25 + └ at /handler_c822920b.sandbox.js:24:19 fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get │ Error: Object does not exist (key=doesn't exist): Error: ENOENT: no such file or directory, open '../../../examples/tests/error/target/test/inflight_stacktraces.test.wsim/.state/' - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:15:3 - │ | } - │ | - │ | test \\"bucket failed get\\" { - │ 15 | bucket.get(\\"doesn't exist\\"); - │ | ^ - └ at /inflight_stacktraces.test.w:15:3 + │ at /inflight_stacktraces.test.w:15:3 + │ at handler /handler_c894fc5f.sandbox.js:29:10 + └ at /handler_c894fc5f.sandbox.js:34:19 fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ Error: ouch - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:20:5 - │ | - │ | test \\"throw from closure\\" { - │ | let closure = inflight () => { - │ 20 | throw \\"ouch\\"; - │ | ^ │ at closure /inflight_stacktraces.test.w:20:5 - └ at /inflight_stacktraces.test.w:22:3 + │ at /inflight_stacktraces.test.w:22:3 + │ at handler /handler_c829ffec.sandbox.js:18:25 + └ at /handler_c829ffec.sandbox.js:23:19 Tests 4 failed (4) diff --git a/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md index 0f478ad24ae..f46ae02feeb 100644 --- a/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/sdk_tests/function/invoke.test.w_test_sim.md @@ -6,8 +6,8 @@ log preflight log preflight pass ┌ invoke.test.wsim » root/env0/test:invoke │ log inside test - └ log inside function -contains 2 lines + │ log inside function + └ contains 2 lines pass ┌ invoke.test.wsim » root/env1/test:invoke without inputs and outputs │ no event, no return! └ bang! diff --git a/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_compile_tf-aws.md index 5f08a9977f6..d090b6259a2 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_compile_tf-aws.md @@ -27,7 +27,7 @@ module.exports = function({ $numA, $numB, $strA, $strB }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $arrayA, $arrayB, $arrayC }) { +module.exports = function({ $arrayA, $arrayB }) { class $Closure10 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -35,8 +35,8 @@ module.exports = function({ $arrayA, $arrayB, $arrayC }) { return $obj; } async handle() { - $helpers.assert($helpers.neq($arrayA, $arrayC), "arrayA != arrayC"); - $helpers.assert((!$helpers.neq($arrayA, $arrayB)), "!(arrayA != arrayB)"); + $helpers.assert($helpers.eq($arrayA, $arrayA), "arrayA == arrayA"); + $helpers.assert($helpers.eq($arrayA, $arrayB), "arrayA == arrayB"); } } return $Closure10; @@ -48,7 +48,7 @@ module.exports = function({ $arrayA, $arrayB, $arrayC }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $cat1, $cat2 }) { +module.exports = function({ $arrayA, $arrayB, $arrayC }) { class $Closure11 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -56,8 +56,8 @@ module.exports = function({ $cat1, $cat2 }) { return $obj; } async handle() { - $helpers.assert($helpers.eq($cat1, $cat1), "cat1 == cat1"); - $helpers.assert($helpers.eq($cat1, $cat2), "cat1 == cat2"); + $helpers.assert($helpers.neq($arrayA, $arrayC), "arrayA != arrayC"); + $helpers.assert((!$helpers.neq($arrayA, $arrayB)), "!(arrayA != arrayB)"); } } return $Closure11; @@ -69,7 +69,7 @@ module.exports = function({ $cat1, $cat2 }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $cat1, $cat2, $cat3 }) { +module.exports = function({ $cat1, $cat2 }) { class $Closure12 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -77,8 +77,8 @@ module.exports = function({ $cat1, $cat2, $cat3 }) { return $obj; } async handle() { - $helpers.assert($helpers.neq($cat1, $cat3), "cat1 != cat3"); - $helpers.assert((!$helpers.neq($cat1, $cat2)), "!(cat1 != cat2)"); + $helpers.assert($helpers.eq($cat1, $cat1), "cat1 == cat1"); + $helpers.assert($helpers.eq($cat1, $cat2), "cat1 == cat2"); } } return $Closure12; @@ -86,6 +86,27 @@ module.exports = function({ $cat1, $cat2, $cat3 }) { //# sourceMappingURL=inflight.$Closure12-1.js.map ``` +## inflight.$Closure13-1.js +```js +"use strict"; +const $helpers = require("@winglang/sdk/lib/helpers"); +module.exports = function({ $cat1, $cat2, $cat3 }) { + class $Closure13 { + constructor({ }) { + const $obj = (...args) => this.handle(...args); + Object.setPrototypeOf($obj, this); + return $obj; + } + async handle() { + $helpers.assert($helpers.neq($cat1, $cat3), "cat1 != cat3"); + $helpers.assert((!$helpers.neq($cat1, $cat2)), "!(cat1 != cat2)"); + } + } + return $Closure13; +} +//# sourceMappingURL=inflight.$Closure13-1.js.map +``` + ## inflight.$Closure2-1.js ```js "use strict"; @@ -153,7 +174,7 @@ module.exports = function({ $jsonA, $jsonB, $jsonC }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $setA, $setB }) { +module.exports = function({ $std_Json }) { class $Closure5 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -161,8 +182,8 @@ module.exports = function({ $setA, $setB }) { return $obj; } async handle() { - $helpers.assert($helpers.eq($setA, $setA), "setA == setA"); - $helpers.assert($helpers.eq($setA, $setB), "setA == setB"); + const j = ({"hello": 123, "world": [1, 2, 3]}); + $helpers.assert($helpers.eq(Object.values(j), [123, [1, 2, 3]]), "Json.values(j) == [Json 123, Json [1, 2, 3]]"); } } return $Closure5; @@ -174,7 +195,7 @@ module.exports = function({ $setA, $setB }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $setA, $setB, $setC }) { +module.exports = function({ $setA, $setB }) { class $Closure6 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -182,8 +203,8 @@ module.exports = function({ $setA, $setB, $setC }) { return $obj; } async handle() { - $helpers.assert($helpers.neq($setA, $setC), "setA != setC"); - $helpers.assert((!$helpers.neq($setA, $setB)), "!(setA != setB)"); + $helpers.assert($helpers.eq($setA, $setA), "setA == setA"); + $helpers.assert($helpers.eq($setA, $setB), "setA == setB"); } } return $Closure6; @@ -195,7 +216,7 @@ module.exports = function({ $setA, $setB, $setC }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $mapA, $mapB }) { +module.exports = function({ $setA, $setB, $setC }) { class $Closure7 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -203,8 +224,8 @@ module.exports = function({ $mapA, $mapB }) { return $obj; } async handle() { - $helpers.assert($helpers.eq($mapA, $mapA), "mapA == mapA"); - $helpers.assert($helpers.eq($mapA, $mapB), "mapA == mapB"); + $helpers.assert($helpers.neq($setA, $setC), "setA != setC"); + $helpers.assert((!$helpers.neq($setA, $setB)), "!(setA != setB)"); } } return $Closure7; @@ -216,7 +237,7 @@ module.exports = function({ $mapA, $mapB }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $mapA, $mapB, $mapC }) { +module.exports = function({ $mapA, $mapB }) { class $Closure8 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -224,8 +245,8 @@ module.exports = function({ $mapA, $mapB, $mapC }) { return $obj; } async handle() { - $helpers.assert($helpers.neq($mapA, $mapC), "mapA != mapC"); - $helpers.assert((!$helpers.neq($mapA, $mapB)), "!(mapA != mapB)"); + $helpers.assert($helpers.eq($mapA, $mapA), "mapA == mapA"); + $helpers.assert($helpers.eq($mapA, $mapB), "mapA == mapB"); } } return $Closure8; @@ -237,7 +258,7 @@ module.exports = function({ $mapA, $mapB, $mapC }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $arrayA, $arrayB }) { +module.exports = function({ $mapA, $mapB, $mapC }) { class $Closure9 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -245,8 +266,8 @@ module.exports = function({ $arrayA, $arrayB }) { return $obj; } async handle() { - $helpers.assert($helpers.eq($arrayA, $arrayA), "arrayA == arrayA"); - $helpers.assert($helpers.eq($arrayA, $arrayB), "arrayA == arrayB"); + $helpers.assert($helpers.neq($mapA, $mapC), "mapA != mapC"); + $helpers.assert((!$helpers.neq($mapA, $mapB)), "!(mapA != mapB)"); } } return $Closure9; @@ -461,8 +482,7 @@ class $Root extends $stdlib.std.Resource { static _toInflightType() { return ` require("${$helpers.normalPath(__dirname)}/inflight.$Closure5-1.js")({ - $setA: ${$stdlib.core.liftObject(setA)}, - $setB: ${$stdlib.core.liftObject(setB)}, + $std_Json: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(std.Json, "@winglang/sdk/std", "Json"))}, }) `; } @@ -477,6 +497,40 @@ class $Root extends $stdlib.std.Resource { })()) `; } + get _liftMap() { + return ({ + "handle": [ + ], + "$inflight_init": [ + ], + }); + } + } + class $Closure6 extends $stdlib.std.AutoIdResource { + _id = $stdlib.core.closureId(); + constructor($scope, $id, ) { + super($scope, $id); + $helpers.nodeof(this).hidden = true; + } + static _toInflightType() { + return ` + require("${$helpers.normalPath(__dirname)}/inflight.$Closure6-1.js")({ + $setA: ${$stdlib.core.liftObject(setA)}, + $setB: ${$stdlib.core.liftObject(setB)}, + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const $Closure6Client = ${$Closure6._toInflightType()}; + const client = new $Closure6Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } get _liftMap() { return ({ "handle": [ @@ -490,7 +544,7 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure6 extends $stdlib.std.AutoIdResource { + class $Closure7 extends $stdlib.std.AutoIdResource { _id = $stdlib.core.closureId(); constructor($scope, $id, ) { super($scope, $id); @@ -498,7 +552,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType() { return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure6-1.js")({ + require("${$helpers.normalPath(__dirname)}/inflight.$Closure7-1.js")({ $setA: ${$stdlib.core.liftObject(setA)}, $setB: ${$stdlib.core.liftObject(setB)}, $setC: ${$stdlib.core.liftObject(setC)}, @@ -508,8 +562,8 @@ class $Root extends $stdlib.std.Resource { _toInflight() { return ` (await (async () => { - const $Closure6Client = ${$Closure6._toInflightType()}; - const client = new $Closure6Client({ + const $Closure7Client = ${$Closure7._toInflightType()}; + const client = new $Closure7Client({ }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -531,7 +585,7 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure7 extends $stdlib.std.AutoIdResource { + class $Closure8 extends $stdlib.std.AutoIdResource { _id = $stdlib.core.closureId(); constructor($scope, $id, ) { super($scope, $id); @@ -539,7 +593,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType() { return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure7-1.js")({ + require("${$helpers.normalPath(__dirname)}/inflight.$Closure8-1.js")({ $mapA: ${$stdlib.core.liftObject(mapA)}, $mapB: ${$stdlib.core.liftObject(mapB)}, }) @@ -548,8 +602,8 @@ class $Root extends $stdlib.std.Resource { _toInflight() { return ` (await (async () => { - const $Closure7Client = ${$Closure7._toInflightType()}; - const client = new $Closure7Client({ + const $Closure8Client = ${$Closure8._toInflightType()}; + const client = new $Closure8Client({ }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -569,7 +623,7 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure8 extends $stdlib.std.AutoIdResource { + class $Closure9 extends $stdlib.std.AutoIdResource { _id = $stdlib.core.closureId(); constructor($scope, $id, ) { super($scope, $id); @@ -577,7 +631,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType() { return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure8-1.js")({ + require("${$helpers.normalPath(__dirname)}/inflight.$Closure9-1.js")({ $mapA: ${$stdlib.core.liftObject(mapA)}, $mapB: ${$stdlib.core.liftObject(mapB)}, $mapC: ${$stdlib.core.liftObject(mapC)}, @@ -587,8 +641,8 @@ class $Root extends $stdlib.std.Resource { _toInflight() { return ` (await (async () => { - const $Closure8Client = ${$Closure8._toInflightType()}; - const client = new $Closure8Client({ + const $Closure9Client = ${$Closure9._toInflightType()}; + const client = new $Closure9Client({ }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -610,7 +664,7 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure9 extends $stdlib.std.AutoIdResource { + class $Closure10 extends $stdlib.std.AutoIdResource { _id = $stdlib.core.closureId(); constructor($scope, $id, ) { super($scope, $id); @@ -618,7 +672,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType() { return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure9-1.js")({ + require("${$helpers.normalPath(__dirname)}/inflight.$Closure10-1.js")({ $arrayA: ${$stdlib.core.liftObject(arrayA)}, $arrayB: ${$stdlib.core.liftObject(arrayB)}, }) @@ -627,8 +681,8 @@ class $Root extends $stdlib.std.Resource { _toInflight() { return ` (await (async () => { - const $Closure9Client = ${$Closure9._toInflightType()}; - const client = new $Closure9Client({ + const $Closure10Client = ${$Closure10._toInflightType()}; + const client = new $Closure10Client({ }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -648,7 +702,7 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure10 extends $stdlib.std.AutoIdResource { + class $Closure11 extends $stdlib.std.AutoIdResource { _id = $stdlib.core.closureId(); constructor($scope, $id, ) { super($scope, $id); @@ -656,7 +710,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType() { return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure10-1.js")({ + require("${$helpers.normalPath(__dirname)}/inflight.$Closure11-1.js")({ $arrayA: ${$stdlib.core.liftObject(arrayA)}, $arrayB: ${$stdlib.core.liftObject(arrayB)}, $arrayC: ${$stdlib.core.liftObject(arrayC)}, @@ -666,8 +720,8 @@ class $Root extends $stdlib.std.Resource { _toInflight() { return ` (await (async () => { - const $Closure10Client = ${$Closure10._toInflightType()}; - const client = new $Closure10Client({ + const $Closure11Client = ${$Closure11._toInflightType()}; + const client = new $Closure11Client({ }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -689,7 +743,7 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure11 extends $stdlib.std.AutoIdResource { + class $Closure12 extends $stdlib.std.AutoIdResource { _id = $stdlib.core.closureId(); constructor($scope, $id, ) { super($scope, $id); @@ -697,7 +751,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType() { return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure11-1.js")({ + require("${$helpers.normalPath(__dirname)}/inflight.$Closure12-1.js")({ $cat1: ${$stdlib.core.liftObject(cat1)}, $cat2: ${$stdlib.core.liftObject(cat2)}, }) @@ -706,8 +760,8 @@ class $Root extends $stdlib.std.Resource { _toInflight() { return ` (await (async () => { - const $Closure11Client = ${$Closure11._toInflightType()}; - const client = new $Closure11Client({ + const $Closure12Client = ${$Closure12._toInflightType()}; + const client = new $Closure12Client({ }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -727,7 +781,7 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure12 extends $stdlib.std.AutoIdResource { + class $Closure13 extends $stdlib.std.AutoIdResource { _id = $stdlib.core.closureId(); constructor($scope, $id, ) { super($scope, $id); @@ -735,7 +789,7 @@ class $Root extends $stdlib.std.Resource { } static _toInflightType() { return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure12-1.js")({ + require("${$helpers.normalPath(__dirname)}/inflight.$Closure13-1.js")({ $cat1: ${$stdlib.core.liftObject(cat1)}, $cat2: ${$stdlib.core.liftObject(cat2)}, $cat3: ${$stdlib.core.liftObject(cat3)}, @@ -745,8 +799,8 @@ class $Root extends $stdlib.std.Resource { _toInflight() { return ` (await (async () => { - const $Closure12Client = ${$Closure12._toInflightType()}; - const client = new $Closure12Client({ + const $Closure13Client = ${$Closure13._toInflightType()}; + const client = new $Closure13Client({ }); if (client.$inflight_init) { await client.$inflight_init(); } return client; @@ -781,26 +835,27 @@ class $Root extends $stdlib.std.Resource { const jsonC = [1, 2, 3]; this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Json with the same value", new $Closure3(this, "$Closure3")); this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Json with different values", new $Closure4(this, "$Closure4")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Json.values equality", new $Closure5(this, "$Closure5")); const setA = new Set([1, 2, 3]); const setB = new Set([1, 2, 3]); const setC = new Set([4, 5, 6]); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Set types with the same value", new $Closure5(this, "$Closure5")); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Set types with different values", new $Closure6(this, "$Closure6")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Set types with the same value", new $Closure6(this, "$Closure6")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Set types with different values", new $Closure7(this, "$Closure7")); const mapA = ({["a"]: 1, ["b"]: 2}); const mapB = ({["a"]: 1, ["b"]: 2}); const mapC = ({["c"]: 10, ["b"]: 2}); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Map with the same value", new $Closure7(this, "$Closure7")); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Map with different values", new $Closure8(this, "$Closure8")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Map with the same value", new $Closure8(this, "$Closure8")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Map with different values", new $Closure9(this, "$Closure9")); const arrayA = [1, 2, 3]; const arrayB = [1, 2, 3]; const arrayC = [4, 5, 6]; - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Array with the same value", new $Closure9(this, "$Closure9")); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Array with different values", new $Closure10(this, "$Closure10")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Array with the same value", new $Closure10(this, "$Closure10")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Array with different values", new $Closure11(this, "$Closure11")); const cat1 = ({"name": "Mittens", "age": 3}); const cat2 = ({"name": "Mittens", "age": 3}); const cat3 = ({"name": "Simba", "age": 5}); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Struct with the same value", new $Closure11(this, "$Closure11")); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Struct with different values", new $Closure12(this, "$Closure12")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Struct with the same value", new $Closure12(this, "$Closure12")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Struct with different values", new $Closure13(this, "$Closure13")); } } const $PlatformManager = new $stdlib.platform.PlatformManager({platformPaths: $platforms}); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_test_sim.md index 687fd06e3d5..aac00f0fc34 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/deep_equality.test.w_test_sim.md @@ -4,19 +4,20 @@ ```log pass ─ deep_equality.test.wsim » root/env0/test:Primitive types with the same value pass ─ deep_equality.test.wsim » root/env1/test:Primitive types with different values -pass ─ deep_equality.test.wsim » root/env10/test:Struct with the same value -pass ─ deep_equality.test.wsim » root/env11/test:Struct with different values +pass ─ deep_equality.test.wsim » root/env10/test:Array with different values +pass ─ deep_equality.test.wsim » root/env11/test:Struct with the same value +pass ─ deep_equality.test.wsim » root/env12/test:Struct with different values pass ─ deep_equality.test.wsim » root/env2/test:Json with the same value pass ─ deep_equality.test.wsim » root/env3/test:Json with different values -pass ─ deep_equality.test.wsim » root/env4/test:Set types with the same value -pass ─ deep_equality.test.wsim » root/env5/test:Set types with different values -pass ─ deep_equality.test.wsim » root/env6/test:Map with the same value -pass ─ deep_equality.test.wsim » root/env7/test:Map with different values -pass ─ deep_equality.test.wsim » root/env8/test:Array with the same value -pass ─ deep_equality.test.wsim » root/env9/test:Array with different values +pass ─ deep_equality.test.wsim » root/env4/test:Json.values equality +pass ─ deep_equality.test.wsim » root/env5/test:Set types with the same value +pass ─ deep_equality.test.wsim » root/env6/test:Set types with different values +pass ─ deep_equality.test.wsim » root/env7/test:Map with the same value +pass ─ deep_equality.test.wsim » root/env8/test:Map with different values +pass ─ deep_equality.test.wsim » root/env9/test:Array with the same value -Tests 12 passed (12) +Tests 13 passed (13) Test Files 1 passed (1) Duration ``` diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md index 34c3103b360..f3c1f7a78c4 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md @@ -46,7 +46,7 @@ module.exports = function({ $foo }) { ```js "use strict"; const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $expect_Util, $fn, $fn2, $sim }) { +module.exports = function({ $expect_Util, $fn, $fn2 }) { class $Closure3 { constructor({ }) { const $obj = (...args) => this.handle(...args); @@ -59,11 +59,7 @@ module.exports = function({ $expect_Util, $fn, $fn2, $sim }) { const z = (await $fn2.invoke("")); (await $expect_Util.equal(x, "100")); (await $expect_Util.equal(z, "100-fn2")); - if ($sim) { - (await $expect_Util.equal(y, "101")); - (await $expect_Util.equal(z, "100-fn2")); - console.log("client has been reused"); - } + $helpers.assert(($helpers.eq(y, "100") || $helpers.eq(y, "101")), "y == \"100\" || y == \"101\""); } } return $Closure3; @@ -71,6 +67,50 @@ module.exports = function({ $expect_Util, $fn, $fn2, $sim }) { //# sourceMappingURL=inflight.$Closure3-1.js.map ``` +## inflight.$Closure4-1.js +```js +"use strict"; +const $helpers = require("@winglang/sdk/lib/helpers"); +module.exports = function({ $foo, $std_Duration, $util_Util }) { + class $Closure4 { + constructor({ }) { + const $obj = (...args) => this.handle(...args); + Object.setPrototypeOf($obj, this); + return $obj; + } + async handle() { + const n = (await $foo.inc()); + (await $util_Util.sleep((await $std_Duration.fromSeconds(3)))); + $helpers.assert($helpers.eq(n, (await $foo.get())), "n == foo.get()"); + } + } + return $Closure4; +} +//# sourceMappingURL=inflight.$Closure4-1.js.map +``` + +## inflight.$Closure5-1.js +```js +"use strict"; +const $helpers = require("@winglang/sdk/lib/helpers"); +module.exports = function({ $incAndCheck, $std_Duration, $util_Util }) { + class $Closure5 { + constructor({ }) { + const $obj = (...args) => this.handle(...args); + Object.setPrototypeOf($obj, this); + return $obj; + } + async handle() { + (await $incAndCheck.invokeAsync()); + (await $util_Util.sleep((await $std_Duration.fromSeconds(1)))); + (await $incAndCheck.invoke()); + } + } + return $Closure5; +} +//# sourceMappingURL=inflight.$Closure5-1.js.map +``` + ## inflight.Foo-1.js ```js "use strict"; @@ -83,6 +123,9 @@ module.exports = function({ }) { this.n += 1; return this.n; } + async get() { + return this.n; + } async $inflight_init() { this.n = 99; } @@ -129,6 +172,16 @@ module.exports = function({ }) { }, "name": "/aws/lambda/fn2-c892a4c6", "retention_in_days": 30 + }, + "incAndCheck_CloudwatchLogGroup_01665AEE": { + "//": { + "metadata": { + "path": "root/Default/Default/incAndCheck/CloudwatchLogGroup", + "uniqueId": "incAndCheck_CloudwatchLogGroup_01665AEE" + } + }, + "name": "/aws/lambda/incAndCheck-c8164d4e", + "retention_in_days": 30 } }, "aws_iam_role": { @@ -149,6 +202,15 @@ module.exports = function({ }) { } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" + }, + "incAndCheck_IamRole_67B3672C": { + "//": { + "metadata": { + "path": "root/Default/Default/incAndCheck/IamRole", + "uniqueId": "incAndCheck_IamRole_67B3672C" + } + }, + "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -171,6 +233,16 @@ module.exports = function({ }) { }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.fn2_IamRole_DE8D96D2.name}" + }, + "incAndCheck_IamRolePolicy_6D4DA8EC": { + "//": { + "metadata": { + "path": "root/Default/Default/incAndCheck/IamRolePolicy", + "uniqueId": "incAndCheck_IamRolePolicy_6D4DA8EC" + } + }, + "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", + "role": "${aws_iam_role.incAndCheck_IamRole_67B3672C.name}" } }, "aws_iam_role_policy_attachment": { @@ -193,6 +265,16 @@ module.exports = function({ }) { }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.fn2_IamRole_DE8D96D2.name}" + }, + "incAndCheck_IamRolePolicyAttachment_D8077C87": { + "//": { + "metadata": { + "path": "root/Default/Default/incAndCheck/IamRolePolicyAttachment", + "uniqueId": "incAndCheck_IamRolePolicyAttachment_D8077C87" + } + }, + "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "role": "${aws_iam_role.incAndCheck_IamRole_67B3672C.name}" } }, "aws_lambda_function": { @@ -257,6 +339,37 @@ module.exports = function({ }) { "security_group_ids": [], "subnet_ids": [] } + }, + "incAndCheck": { + "//": { + "metadata": { + "path": "root/Default/Default/incAndCheck/Default", + "uniqueId": "incAndCheck" + } + }, + "architectures": [ + "arm64" + ], + "environment": { + "variables": { + "NODE_OPTIONS": "--enable-source-maps", + "WING_FUNCTION_NAME": "incAndCheck-c8164d4e", + "WING_TARGET": "tf-aws" + } + }, + "function_name": "incAndCheck-c8164d4e", + "handler": "index.handler", + "memory_size": 1024, + "publish": true, + "role": "${aws_iam_role.incAndCheck_IamRole_67B3672C.arn}", + "runtime": "nodejs20.x", + "s3_bucket": "${aws_s3_bucket.Code.bucket}", + "s3_key": "${aws_s3_object.incAndCheck_S3Object_C6E37371.key}", + "timeout": 60, + "vpc_config": { + "security_group_ids": [], + "subnet_ids": [] + } } }, "aws_s3_bucket": { @@ -292,6 +405,17 @@ module.exports = function({ }) { "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" + }, + "incAndCheck_S3Object_C6E37371": { + "//": { + "metadata": { + "path": "root/Default/Default/incAndCheck/S3Object", + "uniqueId": "incAndCheck_S3Object_C6E37371" + } + }, + "bucket": "${aws_s3_bucket.Code.bucket}", + "key": "", + "source": "" } } } @@ -338,6 +462,8 @@ class $Root extends $stdlib.std.Resource { return ({ "inc": [ ], + "get": [ + ], "$inflight_init": [ ], "n": [ @@ -427,7 +553,6 @@ class $Root extends $stdlib.std.Resource { $expect_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(expect.Util, "@winglang/sdk/expect", "Util"))}, $fn: ${$stdlib.core.liftObject(fn)}, $fn2: ${$stdlib.core.liftObject(fn2)}, - $sim: ${$stdlib.core.liftObject(sim)}, }) `; } @@ -447,12 +572,84 @@ class $Root extends $stdlib.std.Resource { "handle": [ [fn, ["invoke"]], [fn2, ["invoke"]], - [sim, []], ], "$inflight_init": [ [fn, []], [fn2, []], - [sim, []], + ], + }); + } + } + class $Closure4 extends $stdlib.std.AutoIdResource { + _id = $stdlib.core.closureId(); + constructor($scope, $id, ) { + super($scope, $id); + $helpers.nodeof(this).hidden = true; + } + static _toInflightType() { + return ` + require("${$helpers.normalPath(__dirname)}/inflight.$Closure4-1.js")({ + $foo: ${$stdlib.core.liftObject(foo)}, + $std_Duration: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(std.Duration, "@winglang/sdk/std", "Duration"))}, + $util_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(util.Util, "@winglang/sdk/util", "Util"))}, + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const $Closure4Client = ${$Closure4._toInflightType()}; + const client = new $Closure4Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } + get _liftMap() { + return ({ + "handle": [ + [foo, ["get", "inc"]], + ], + "$inflight_init": [ + [foo, []], + ], + }); + } + } + class $Closure5 extends $stdlib.std.AutoIdResource { + _id = $stdlib.core.closureId(); + constructor($scope, $id, ) { + super($scope, $id); + $helpers.nodeof(this).hidden = true; + } + static _toInflightType() { + return ` + require("${$helpers.normalPath(__dirname)}/inflight.$Closure5-1.js")({ + $incAndCheck: ${$stdlib.core.liftObject(incAndCheck)}, + $std_Duration: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(std.Duration, "@winglang/sdk/std", "Duration"))}, + $util_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(util.Util, "@winglang/sdk/util", "Util"))}, + }) + `; + } + _toInflight() { + return ` + (await (async () => { + const $Closure5Client = ${$Closure5._toInflightType()}; + const client = new $Closure5Client({ + }); + if (client.$inflight_init) { await client.$inflight_init(); } + return client; + })()) + `; + } + get _liftMap() { + return ({ + "handle": [ + [incAndCheck, ["invoke", "invokeAsync"]], + ], + "$inflight_init": [ + [incAndCheck, []], ], }); } @@ -462,6 +659,8 @@ class $Root extends $stdlib.std.Resource { const fn2 = this.node.root.new("@winglang/sdk.cloud.Function", cloud.Function, this, "fn2", new $Closure2(this, "$Closure2")); const sim = $helpers.eq((util.Util.env("WING_TARGET")), "sim"); this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:single instance of Foo", new $Closure3(this, "$Closure3")); + const incAndCheck = this.node.root.new("@winglang/sdk.cloud.Function", cloud.Function, this, "incAndCheck", new $Closure4(this, "$Closure4")); + this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Foo state is not shared between concurrent function invocations", new $Closure5(this, "$Closure5")); } } const $PlatformManager = new $stdlib.platform.PlatformManager({platformPaths: $platforms}); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md index 94cccf3d190..46c0e3d1fa5 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md @@ -2,11 +2,11 @@ ## stdout.log ```log -pass ┌ inflight_handler_singleton.test.wsim » root/env0/test:single instance of Foo - └ client has been reused +pass ─ inflight_handler_singleton.test.wsim » root/env0/test:single instance of Foo +pass ─ inflight_handler_singleton.test.wsim » root/env1/test:Foo state is not shared between concurrent function invocations -Tests 1 passed (1) +Tests 2 passed (2) Test Files 1 passed (1) Duration ``` From 25d767ba4d5b4acdb16050d48b622236fec6610e Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 20:07:01 -0500 Subject: [PATCH 12/27] remove part of test --- .../tests/valid/inflight_handler_singleton.test.w | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/examples/tests/valid/inflight_handler_singleton.test.w b/examples/tests/valid/inflight_handler_singleton.test.w index 8d0520ab72e..7003511e4d0 100644 --- a/examples/tests/valid/inflight_handler_singleton.test.w +++ b/examples/tests/valid/inflight_handler_singleton.test.w @@ -44,17 +44,3 @@ test "single instance of Foo" { // was reused or not between the two calls. assert(y == "100" || y == "101"); } - -// a function that takes at least three seconds to run -let incAndCheck = new cloud.Function(inflight () => { - let n = foo.inc(); - util.sleep(3s); - assert(n == foo.get()); -}) as "incAndCheck"; - -test "Foo state is not shared between concurrent function invocations" { - // start two invocations of fn, staggering them by 1 second - incAndCheck.invokeAsync(); - util.sleep(1s); - incAndCheck.invoke(); -} From e74e55674fbca4c0caf44b2a0ea15180708dd7c5 Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Wed, 6 Mar 2024 01:18:41 +0000 Subject: [PATCH 13/27] chore: self mutation (e2e-2of2.diff) Signed-off-by: monada-bot[bot] --- tools/hangar/__snapshots__/error.ts.snap | 24 +++ ...handler_singleton.test.w_compile_tf-aws.md | 201 ------------------ ...light_handler_singleton.test.w_test_sim.md | 5 +- 3 files changed, 26 insertions(+), 204 deletions(-) diff --git a/tools/hangar/__snapshots__/error.ts.snap b/tools/hangar/__snapshots__/error.ts.snap index a7fec3095c0..5dcbe47754e 100644 --- a/tools/hangar/__snapshots__/error.ts.snap +++ b/tools/hangar/__snapshots__/error.ts.snap @@ -20,6 +20,12 @@ Duration " exports[`inflight_stacktraces.test.w 1`] = ` "fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert │ Error: assertion failed: false + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:7:3 + │ | let bucket = new cloud.Bucket(); + │ | + │ | test \\"assert\\" { + │ 7 | assert(false); + │ | ^ │ at /inflight_stacktraces.test.w:7:3 │ at handler /handler_c8b175d2.sandbox.js:18:25 └ at /handler_c8b175d2.sandbox.js:23:19 @@ -28,16 +34,34 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ │ 1 !== 2 │ + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:11:3 + │ | } + │ | + │ | test \\"expect.equal\\" { + │ 11 | expect.equal(1,2 ); + │ | ^ │ at /inflight_stacktraces.test.w:11:3 │ at handler /handler_c822920b.sandbox.js:19:25 └ at /handler_c822920b.sandbox.js:24:19 fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get │ Error: Object does not exist (key=doesn't exist): Error: ENOENT: no such file or directory, open '../../../examples/tests/error/target/test/inflight_stacktraces.test.wsim/.state/' + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:15:3 + │ | } + │ | + │ | test \\"bucket failed get\\" { + │ 15 | bucket.get(\\"doesn't exist\\"); + │ | ^ │ at /inflight_stacktraces.test.w:15:3 │ at handler /handler_c894fc5f.sandbox.js:29:10 └ at /handler_c894fc5f.sandbox.js:34:19 fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ Error: ouch + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:20:5 + │ | + │ | test \\"throw from closure\\" { + │ | let closure = inflight () => { + │ 20 | throw \\"ouch\\"; + │ | ^ │ at closure /inflight_stacktraces.test.w:20:5 │ at /inflight_stacktraces.test.w:22:3 │ at handler /handler_c829ffec.sandbox.js:18:25 diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md index f3c1f7a78c4..80bdfa65a89 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md @@ -67,50 +67,6 @@ module.exports = function({ $expect_Util, $fn, $fn2 }) { //# sourceMappingURL=inflight.$Closure3-1.js.map ``` -## inflight.$Closure4-1.js -```js -"use strict"; -const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $foo, $std_Duration, $util_Util }) { - class $Closure4 { - constructor({ }) { - const $obj = (...args) => this.handle(...args); - Object.setPrototypeOf($obj, this); - return $obj; - } - async handle() { - const n = (await $foo.inc()); - (await $util_Util.sleep((await $std_Duration.fromSeconds(3)))); - $helpers.assert($helpers.eq(n, (await $foo.get())), "n == foo.get()"); - } - } - return $Closure4; -} -//# sourceMappingURL=inflight.$Closure4-1.js.map -``` - -## inflight.$Closure5-1.js -```js -"use strict"; -const $helpers = require("@winglang/sdk/lib/helpers"); -module.exports = function({ $incAndCheck, $std_Duration, $util_Util }) { - class $Closure5 { - constructor({ }) { - const $obj = (...args) => this.handle(...args); - Object.setPrototypeOf($obj, this); - return $obj; - } - async handle() { - (await $incAndCheck.invokeAsync()); - (await $util_Util.sleep((await $std_Duration.fromSeconds(1)))); - (await $incAndCheck.invoke()); - } - } - return $Closure5; -} -//# sourceMappingURL=inflight.$Closure5-1.js.map -``` - ## inflight.Foo-1.js ```js "use strict"; @@ -172,16 +128,6 @@ module.exports = function({ }) { }, "name": "/aws/lambda/fn2-c892a4c6", "retention_in_days": 30 - }, - "incAndCheck_CloudwatchLogGroup_01665AEE": { - "//": { - "metadata": { - "path": "root/Default/Default/incAndCheck/CloudwatchLogGroup", - "uniqueId": "incAndCheck_CloudwatchLogGroup_01665AEE" - } - }, - "name": "/aws/lambda/incAndCheck-c8164d4e", - "retention_in_days": 30 } }, "aws_iam_role": { @@ -202,15 +148,6 @@ module.exports = function({ }) { } }, "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" - }, - "incAndCheck_IamRole_67B3672C": { - "//": { - "metadata": { - "path": "root/Default/Default/incAndCheck/IamRole", - "uniqueId": "incAndCheck_IamRole_67B3672C" - } - }, - "assume_role_policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"sts:AssumeRole\",\"Principal\":{\"Service\":\"lambda.amazonaws.com\"},\"Effect\":\"Allow\"}]}" } }, "aws_iam_role_policy": { @@ -233,16 +170,6 @@ module.exports = function({ }) { }, "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", "role": "${aws_iam_role.fn2_IamRole_DE8D96D2.name}" - }, - "incAndCheck_IamRolePolicy_6D4DA8EC": { - "//": { - "metadata": { - "path": "root/Default/Default/incAndCheck/IamRolePolicy", - "uniqueId": "incAndCheck_IamRolePolicy_6D4DA8EC" - } - }, - "policy": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"none:null\",\"Resource\":\"*\"}]}", - "role": "${aws_iam_role.incAndCheck_IamRole_67B3672C.name}" } }, "aws_iam_role_policy_attachment": { @@ -265,16 +192,6 @@ module.exports = function({ }) { }, "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "role": "${aws_iam_role.fn2_IamRole_DE8D96D2.name}" - }, - "incAndCheck_IamRolePolicyAttachment_D8077C87": { - "//": { - "metadata": { - "path": "root/Default/Default/incAndCheck/IamRolePolicyAttachment", - "uniqueId": "incAndCheck_IamRolePolicyAttachment_D8077C87" - } - }, - "policy_arn": "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "role": "${aws_iam_role.incAndCheck_IamRole_67B3672C.name}" } }, "aws_lambda_function": { @@ -339,37 +256,6 @@ module.exports = function({ }) { "security_group_ids": [], "subnet_ids": [] } - }, - "incAndCheck": { - "//": { - "metadata": { - "path": "root/Default/Default/incAndCheck/Default", - "uniqueId": "incAndCheck" - } - }, - "architectures": [ - "arm64" - ], - "environment": { - "variables": { - "NODE_OPTIONS": "--enable-source-maps", - "WING_FUNCTION_NAME": "incAndCheck-c8164d4e", - "WING_TARGET": "tf-aws" - } - }, - "function_name": "incAndCheck-c8164d4e", - "handler": "index.handler", - "memory_size": 1024, - "publish": true, - "role": "${aws_iam_role.incAndCheck_IamRole_67B3672C.arn}", - "runtime": "nodejs20.x", - "s3_bucket": "${aws_s3_bucket.Code.bucket}", - "s3_key": "${aws_s3_object.incAndCheck_S3Object_C6E37371.key}", - "timeout": 60, - "vpc_config": { - "security_group_ids": [], - "subnet_ids": [] - } } }, "aws_s3_bucket": { @@ -405,17 +291,6 @@ module.exports = function({ }) { "bucket": "${aws_s3_bucket.Code.bucket}", "key": "", "source": "" - }, - "incAndCheck_S3Object_C6E37371": { - "//": { - "metadata": { - "path": "root/Default/Default/incAndCheck/S3Object", - "uniqueId": "incAndCheck_S3Object_C6E37371" - } - }, - "bucket": "${aws_s3_bucket.Code.bucket}", - "key": "", - "source": "" } } } @@ -580,87 +455,11 @@ class $Root extends $stdlib.std.Resource { }); } } - class $Closure4 extends $stdlib.std.AutoIdResource { - _id = $stdlib.core.closureId(); - constructor($scope, $id, ) { - super($scope, $id); - $helpers.nodeof(this).hidden = true; - } - static _toInflightType() { - return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure4-1.js")({ - $foo: ${$stdlib.core.liftObject(foo)}, - $std_Duration: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(std.Duration, "@winglang/sdk/std", "Duration"))}, - $util_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(util.Util, "@winglang/sdk/util", "Util"))}, - }) - `; - } - _toInflight() { - return ` - (await (async () => { - const $Closure4Client = ${$Closure4._toInflightType()}; - const client = new $Closure4Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `; - } - get _liftMap() { - return ({ - "handle": [ - [foo, ["get", "inc"]], - ], - "$inflight_init": [ - [foo, []], - ], - }); - } - } - class $Closure5 extends $stdlib.std.AutoIdResource { - _id = $stdlib.core.closureId(); - constructor($scope, $id, ) { - super($scope, $id); - $helpers.nodeof(this).hidden = true; - } - static _toInflightType() { - return ` - require("${$helpers.normalPath(__dirname)}/inflight.$Closure5-1.js")({ - $incAndCheck: ${$stdlib.core.liftObject(incAndCheck)}, - $std_Duration: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(std.Duration, "@winglang/sdk/std", "Duration"))}, - $util_Util: ${$stdlib.core.liftObject($stdlib.core.toLiftableModuleType(util.Util, "@winglang/sdk/util", "Util"))}, - }) - `; - } - _toInflight() { - return ` - (await (async () => { - const $Closure5Client = ${$Closure5._toInflightType()}; - const client = new $Closure5Client({ - }); - if (client.$inflight_init) { await client.$inflight_init(); } - return client; - })()) - `; - } - get _liftMap() { - return ({ - "handle": [ - [incAndCheck, ["invoke", "invokeAsync"]], - ], - "$inflight_init": [ - [incAndCheck, []], - ], - }); - } - } const foo = new Foo(this, "Foo"); const fn = this.node.root.new("@winglang/sdk.cloud.Function", cloud.Function, this, "cloud.Function", new $Closure1(this, "$Closure1")); const fn2 = this.node.root.new("@winglang/sdk.cloud.Function", cloud.Function, this, "fn2", new $Closure2(this, "$Closure2")); const sim = $helpers.eq((util.Util.env("WING_TARGET")), "sim"); this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:single instance of Foo", new $Closure3(this, "$Closure3")); - const incAndCheck = this.node.root.new("@winglang/sdk.cloud.Function", cloud.Function, this, "incAndCheck", new $Closure4(this, "$Closure4")); - this.node.root.new("@winglang/sdk.std.Test", std.Test, this, "test:Foo state is not shared between concurrent function invocations", new $Closure5(this, "$Closure5")); } } const $PlatformManager = new $stdlib.platform.PlatformManager({platformPaths: $platforms}); diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md index 46c0e3d1fa5..8c3752eb01a 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_test_sim.md @@ -2,11 +2,10 @@ ## stdout.log ```log -pass ─ inflight_handler_singleton.test.wsim » root/env0/test:single instance of Foo -pass ─ inflight_handler_singleton.test.wsim » root/env1/test:Foo state is not shared between concurrent function invocations +pass ─ inflight_handler_singleton.test.wsim » root/env0/test:single instance of Foo -Tests 2 passed (2) +Tests 1 passed (1) Test Files 1 passed (1) Duration ``` From 02d22623eda3e9297630351b8e86afd51846012d Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 20:45:22 -0500 Subject: [PATCH 14/27] fix stack traces --- examples/tests/valid/inflight_handler_singleton.test.w | 4 ---- libs/wingsdk/src/shared/bundling.ts | 4 ++-- libs/wingsdk/src/shared/sandbox.ts | 8 +++++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/examples/tests/valid/inflight_handler_singleton.test.w b/examples/tests/valid/inflight_handler_singleton.test.w index 7003511e4d0..d5d526a2c28 100644 --- a/examples/tests/valid/inflight_handler_singleton.test.w +++ b/examples/tests/valid/inflight_handler_singleton.test.w @@ -12,10 +12,6 @@ class Foo { this.n += 1; return this.n; } - - pub inflight get(): num { - return this.n; - } } let foo = new Foo(); diff --git a/libs/wingsdk/src/shared/bundling.ts b/libs/wingsdk/src/shared/bundling.ts index 146466c794e..fde8ba216d8 100644 --- a/libs/wingsdk/src/shared/bundling.ts +++ b/libs/wingsdk/src/shared/bundling.ts @@ -72,13 +72,13 @@ export function createBundle( new TextDecoder().decode(esbuild.outputFiles[0].contents) ); if (sourcemapData.sourceRoot) { - sourcemapData.sourceRoot = normalPath(sourcemapData.sourceRoot); + sourcemapData.sourceRoot = normalPath(resolve(sourcemapData.sourceRoot)); } for (const [idx, source] of Object.entries( sourcemapData.sources as string[] )) { - sourcemapData.sources[idx] = normalPath(source); + sourcemapData.sources[idx] = normalPath(resolve(source)); } writeFileSync(outfile, bundleOutput.contents); diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index b552344a4f8..70a1af19d7a 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -104,6 +104,8 @@ process.on("message", async (message) => { this.debugLog("Forking process to run bundled code."); // start a Node.js process that runs the bundled code + // note: unlike the fork(2) POSIX system call, child_process.fork() + // does not clone the current process const child = cp.fork(this.entrypoint, [], { env: this.options.env, stdio: "pipe", @@ -159,9 +161,9 @@ process.on("message", async (message) => { } }); - // Something unexpected happened. "error" could be emitted for any number of reasons - // (the process couldn't be spawned or killed, or a message couldn't be sent), - // so we kill the process with SIGKILL to ensure it's dead, and reject the promise. + // "error" could be emitted for any number of reasons + // (e.g. the process couldn't be spawned or killed, or a message couldn't be sent). + // Since this is unexpected, we kill the process with SIGKILL to ensure it's dead, and reject the promise. child.on("error", (error) => { this.debugLog("Killing process after error."); child.kill("SIGKILL"); From 250b8a217e4e2b72d519231b2b6086bdaf615728 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 21:07:49 -0500 Subject: [PATCH 15/27] try removing undici --- libs/wingsdk/.projen/deps.json | 4 -- libs/wingsdk/.projenrc.ts | 1 - libs/wingsdk/package.json | 2 - libs/wingsdk/src/simulator/client.ts | 54 ++++++++++++++----- .../target-sim/__snapshots__/api.test.ts.snap | 42 +++++++-------- pnpm-lock.yaml | 16 ++---- ...handler_singleton.test.w_compile_tf-aws.md | 5 -- 7 files changed, 64 insertions(+), 60 deletions(-) diff --git a/libs/wingsdk/.projen/deps.json b/libs/wingsdk/.projen/deps.json index 4a2a14462d0..9fd500c9965 100644 --- a/libs/wingsdk/.projen/deps.json +++ b/libs/wingsdk/.projen/deps.json @@ -317,10 +317,6 @@ "name": "ulid", "type": "bundled" }, - { - "name": "undici", - "type": "bundled" - }, { "name": "uuid", "type": "bundled" diff --git a/libs/wingsdk/.projenrc.ts b/libs/wingsdk/.projenrc.ts index 4521f9817ad..8c7642eab67 100644 --- a/libs/wingsdk/.projenrc.ts +++ b/libs/wingsdk/.projenrc.ts @@ -75,7 +75,6 @@ const project = new cdk.JsiiProject({ // simulator dependencies "express", "uuid", - "undici", // using version 3 because starting from version 4, it no longer works with CommonJS. "nanoid@^3.3.6", "cron-parser", diff --git a/libs/wingsdk/package.json b/libs/wingsdk/package.json index ade15c1fc9d..4c21da8e180 100644 --- a/libs/wingsdk/package.json +++ b/libs/wingsdk/package.json @@ -112,7 +112,6 @@ "stacktracey": "^2.1.8", "toml": "^3.0.0", "ulid": "^2.3.0", - "undici": "^6.6.2", "uuid": "^8.3.2", "yaml": "^2.3.2" }, @@ -152,7 +151,6 @@ "stacktracey", "toml", "ulid", - "undici", "uuid", "yaml" ], diff --git a/libs/wingsdk/src/simulator/client.ts b/libs/wingsdk/src/simulator/client.ts index dce5ba370bc..a46262b7f05 100644 --- a/libs/wingsdk/src/simulator/client.ts +++ b/libs/wingsdk/src/simulator/client.ts @@ -1,9 +1,40 @@ +import * as http from "http"; import { deserialize } from "./serialization"; import type { SimulatorServerRequest, SimulatorServerResponse, } from "./simulator"; +interface HttpRequestOptions extends http.RequestOptions { + body?: string; +} + +function makeHttpRequest(options: HttpRequestOptions): Promise { + return new Promise((resolve, reject) => { + const req = http.request(options, (res) => { + let data = ""; + + res.on("data", (chunk) => { + data += chunk; + }); + + res.on("end", () => { + resolve(data); + }); + }); + + req.on("error", (e) => { + reject(e); + }); + + if (options.body !== undefined) { + req.write(options.body); + } + + req.end(); + }); +} + export function makeSimulatorClient(url: string, handle: string) { let proxy: any; let hasThenMethod = true; // assume that the object has a "then" method until proven otherwise @@ -15,24 +46,19 @@ export function makeSimulatorClient(url: string, handle: string) { return async function (...args: any[]) { const body: SimulatorServerRequest = { handle, method, args }; - - // import undici dynamically to reduce the time it takes to load Wing SDK - // undici is used instead of the built-in fetch so that we can customize the - // headers timeouts to be 10 minutes instead of the default 5 seconds - const { fetch, Agent } = await import("undici"); - const resp = await fetch(url + "/v1/call", { + const parsedUrl = new URL(url); + const resp = await makeHttpRequest({ + hostname: parsedUrl.hostname, + port: parsedUrl.port, + path: "/v1/call", method: "POST", - headers: { "Content-Type": "application/json" }, + headers: { + "Content-Type": "application/json", + }, body: JSON.stringify(body), - dispatcher: new Agent({ - keepAliveTimeout: 15 * 60 * 1000, - keepAliveMaxTimeout: 15 * 60 * 1000, - headersTimeout: 15 * 60 * 1000, - bodyTimeout: 15 * 60 * 1000, - }), }); - let parsed: SimulatorServerResponse = deserialize(await resp.text()); + let parsed: SimulatorServerResponse = deserialize(resp); if (parsed.error) { // objects with "then" methods are special-cased by the JS runtime diff --git a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap index 024e61fe721..f54c91bd11a 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap @@ -278,7 +278,7 @@ exports[`api handler can read the request params 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -547,7 +547,7 @@ exports[`api handler can read the request path 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -816,7 +816,7 @@ exports[`api handler can set response headers 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1085,7 +1085,7 @@ exports[`api response returns Content-Type header from inflight 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1354,7 +1354,7 @@ exports[`api response returns default Content-Type header 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1623,25 +1623,25 @@ exports[`api supports every method type 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "Processing "PUT /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "PUT /hello - 200.", "Processing "DELETE /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "DELETE /hello - 200.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "OPTIONS /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "OPTIONS /hello - 200.", "Processing "PATCH /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "PATCH /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2024,7 +2024,7 @@ exports[`api with 'name' & 'age' parameter 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /:name/:age" params={"name":"akhil","age":"23"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil/23\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\",\\"age\\":\\"23\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil/23\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\",\\"age\\":\\"23\\"}}").", "GET /:name/:age - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2310,7 +2310,7 @@ exports[`api with 'name' parameter 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /:name" params={"name":"akhil"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\"}}").", "GET /:name - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2856,10 +2856,10 @@ exports[`api with multiple methods on same route 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "@winglang/sdk.cloud.Function deleted.", @@ -3219,10 +3219,10 @@ exports[`api with multiple routes 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello/world" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello/world - 200.", "Processing "GET /hello/wingnuts" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello/wingnuts - 200.", "@winglang/sdk.sim.EventMapping deleted.", "@winglang/sdk.cloud.Function deleted.", @@ -3582,7 +3582,7 @@ exports[`api with one GET route 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -3851,7 +3851,7 @@ exports[`api with one GET route with request params 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /users/:name" params={"name":"tsuf"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}").", "GET /users/:name - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -4129,7 +4129,7 @@ exports[`api with one POST route, with body 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"content-type\\":\\"application/json\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"25\\"},\\"body\\":\\"{\\\\\\"message\\\\\\":\\\\\\"hello world\\\\\\"}\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"content-type\\":\\"application/json\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"25\\"},\\"body\\":\\"{\\\\\\"message\\\\\\":\\\\\\"hello world\\\\\\"}\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8eeffc36dd3..31a1cf4a417 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1365,9 +1365,6 @@ importers: ulid: specifier: ^2.3.0 version: 2.3.0 - undici: - specifier: ^6.6.2 - version: 6.6.2 uuid: specifier: ^8.3.2 version: 8.3.2 @@ -14361,7 +14358,7 @@ packages: dependencies: semver: 7.5.4 shelljs: 0.8.5 - typescript: 5.5.0-dev.20240304 + typescript: 5.5.0-dev.20240305 dev: true /dset@3.1.2: @@ -22936,8 +22933,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - /typescript@5.5.0-dev.20240304: - resolution: {integrity: sha512-nu7H0CgsNe6Q9dJLsRRKB4E7KNBHuhJVJtC6vwC0GNnunJLGh8ZGtEZzcFx+feNnpAC/TWLs/H5EAea1wruBUg==} + /typescript@5.5.0-dev.20240305: + resolution: {integrity: sha512-ERkltjdukpttYHdXPg6cQAeuQrK1BIZ/QnNXLljBx5r90B+8lZ7pZ1qCL/XHHsUEi0lkVLpf9LPfwEYxie3qcA==} engines: {node: '>=14.17'} hasBin: true dev: true @@ -22988,13 +22985,6 @@ packages: '@fastify/busboy': 2.0.0 dev: false - /undici@6.6.2: - resolution: {integrity: sha512-vSqvUE5skSxQJ5sztTZ/CdeJb1Wq0Hf44hlYMciqHghvz+K88U0l7D6u1VsndoFgskDcnU+nG3gYmMzJVzd9Qg==} - engines: {node: '>=18.0'} - dependencies: - '@fastify/busboy': 2.0.0 - dev: false - /unicode-canonical-property-names-ecmascript@2.0.0: resolution: {integrity: sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==} engines: {node: '>=4'} diff --git a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md index 80bdfa65a89..3e87c254ad7 100644 --- a/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md +++ b/tools/hangar/__snapshots__/test_corpus/valid/inflight_handler_singleton.test.w_compile_tf-aws.md @@ -79,9 +79,6 @@ module.exports = function({ }) { this.n += 1; return this.n; } - async get() { - return this.n; - } async $inflight_init() { this.n = 99; } @@ -337,8 +334,6 @@ class $Root extends $stdlib.std.Resource { return ({ "inc": [ ], - "get": [ - ], "$inflight_init": [ ], "n": [ From f035f5f25f8194ea6cfaadb0afe6116738b70827 Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Wed, 6 Mar 2024 02:21:00 +0000 Subject: [PATCH 16/27] chore: self mutation (build.diff) Signed-off-by: monada-bot[bot] --- .../target-sim/__snapshots__/api.test.ts.snap | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap index f54c91bd11a..024e61fe721 100644 --- a/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap +++ b/libs/wingsdk/test/target-sim/__snapshots__/api.test.ts.snap @@ -278,7 +278,7 @@ exports[`api handler can read the request params 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{\\"foo\\":\\"bar\\",\\"bar\\":\\"baz\\"},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -547,7 +547,7 @@ exports[`api handler can read the request path 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -816,7 +816,7 @@ exports[`api handler can set response headers 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"foo\\":\\"bar\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1085,7 +1085,7 @@ exports[`api response returns Content-Type header from inflight 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1354,7 +1354,7 @@ exports[`api response returns default Content-Type header 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -1623,25 +1623,25 @@ exports[`api supports every method type 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "Processing "PUT /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PUT\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "PUT /hello - 200.", "Processing "DELETE /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"DELETE\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "DELETE /hello - 200.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"close\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"HEAD\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "OPTIONS /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"OPTIONS\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "OPTIONS /hello - 200.", "Processing "PATCH /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"PATCH\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "PATCH /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2024,7 +2024,7 @@ exports[`api with 'name' & 'age' parameter 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /:name/:age" params={"name":"akhil","age":"23"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil/23\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\",\\"age\\":\\"23\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil/23\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\",\\"age\\":\\"23\\"}}").", "GET /:name/:age - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2310,7 +2310,7 @@ exports[`api with 'name' parameter 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /:name" params={"name":"akhil"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/akhil\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"akhil\\"}}").", "GET /:name - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -2856,10 +2856,10 @@ exports[`api with multiple methods on same route 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"0\\"},\\"body\\":\\"\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "@winglang/sdk.cloud.Function deleted.", @@ -3219,10 +3219,10 @@ exports[`api with multiple routes 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello/world" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/world\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello/world - 200.", "Processing "GET /hello/wingnuts" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello/wingnuts\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello/wingnuts - 200.", "@winglang/sdk.sim.EventMapping deleted.", "@winglang/sdk.cloud.Function deleted.", @@ -3582,7 +3582,7 @@ exports[`api with one GET route 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "GET /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -3851,7 +3851,7 @@ exports[`api with one GET route with request params 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "GET /users/:name" params={"name":"tsuf"}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\"},\\"body\\":\\"\\",\\"method\\":\\"GET\\",\\"path\\":\\"/users/tsuf\\",\\"query\\":{},\\"vars\\":{\\"name\\":\\"tsuf\\"}}").", "GET /users/:name - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", @@ -4129,7 +4129,7 @@ exports[`api with one POST route, with body 1`] = ` "@winglang/sdk.sim.EventMapping created.", "@winglang/sdk.cloud.Endpoint created.", "Processing "POST /hello" params={}).", - "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"content-type\\":\\"application/json\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"undici\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"25\\"},\\"body\\":\\"{\\\\\\"message\\\\\\":\\\\\\"hello world\\\\\\"}\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", + "Invoke (payload="{\\"headers\\":{\\"host\\":\\"127.0.0.1:\\",\\"connection\\":\\"keep-alive\\",\\"content-type\\":\\"application/json\\",\\"accept\\":\\"*/*\\",\\"accept-language\\":\\"*\\",\\"sec-fetch-mode\\":\\"cors\\",\\"user-agent\\":\\"node\\",\\"accept-encoding\\":\\"gzip, deflate\\",\\"content-length\\":\\"25\\"},\\"body\\":\\"{\\\\\\"message\\\\\\":\\\\\\"hello world\\\\\\"}\\",\\"method\\":\\"POST\\",\\"path\\":\\"/hello\\",\\"query\\":{},\\"vars\\":{}}").", "POST /hello - 200.", "@winglang/sdk.sim.EventMapping deleted.", "Closing server on http://127.0.0.1:", From 301818d9afc21b3966142f9ba34ea50e88f2e015 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Tue, 5 Mar 2024 21:30:29 -0500 Subject: [PATCH 17/27] try fixing non-existent file error --- libs/wingsdk/src/shared/sandbox.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index 70a1af19d7a..86585b7b1f8 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -48,12 +48,13 @@ export class Sandbox { } public async cleanup() { + await this.createBundlePromise; for (const timeout of this.timeouts) { clearTimeout(timeout); } // Make sure all child processes have exited before cleaning up the sandbox. - for (const child of this.exitingChildren) { - await child; + for (const exitingChild of this.exitingChildren) { + await exitingChild; } } From 4d6b7c48d4fdec0885bee2f4129f631e5500669b Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Wed, 6 Mar 2024 02:48:55 +0000 Subject: [PATCH 18/27] chore: self mutation (e2e-2of2.diff) Signed-off-by: monada-bot[bot] --- tools/hangar/__snapshots__/error.ts.snap | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/tools/hangar/__snapshots__/error.ts.snap b/tools/hangar/__snapshots__/error.ts.snap index 5dcbe47754e..a7fec3095c0 100644 --- a/tools/hangar/__snapshots__/error.ts.snap +++ b/tools/hangar/__snapshots__/error.ts.snap @@ -20,12 +20,6 @@ Duration " exports[`inflight_stacktraces.test.w 1`] = ` "fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert │ Error: assertion failed: false - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:7:3 - │ | let bucket = new cloud.Bucket(); - │ | - │ | test \\"assert\\" { - │ 7 | assert(false); - │ | ^ │ at /inflight_stacktraces.test.w:7:3 │ at handler /handler_c8b175d2.sandbox.js:18:25 └ at /handler_c8b175d2.sandbox.js:23:19 @@ -34,34 +28,16 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ │ 1 !== 2 │ - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:11:3 - │ | } - │ | - │ | test \\"expect.equal\\" { - │ 11 | expect.equal(1,2 ); - │ | ^ │ at /inflight_stacktraces.test.w:11:3 │ at handler /handler_c822920b.sandbox.js:19:25 └ at /handler_c822920b.sandbox.js:24:19 fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get │ Error: Object does not exist (key=doesn't exist): Error: ENOENT: no such file or directory, open '../../../examples/tests/error/target/test/inflight_stacktraces.test.wsim/.state/' - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:15:3 - │ | } - │ | - │ | test \\"bucket failed get\\" { - │ 15 | bucket.get(\\"doesn't exist\\"); - │ | ^ │ at /inflight_stacktraces.test.w:15:3 │ at handler /handler_c894fc5f.sandbox.js:29:10 └ at /handler_c894fc5f.sandbox.js:34:19 fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ Error: ouch - │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:20:5 - │ | - │ | test \\"throw from closure\\" { - │ | let closure = inflight () => { - │ 20 | throw \\"ouch\\"; - │ | ^ │ at closure /inflight_stacktraces.test.w:20:5 │ at /inflight_stacktraces.test.w:22:3 │ at handler /handler_c829ffec.sandbox.js:18:25 From 88724dad2b3a4c5eeccae4f3aa8e2d7d89d3bbd5 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Wed, 6 Mar 2024 11:55:58 -0500 Subject: [PATCH 19/27] disable source maps on child process --- .../tests/error/inflight_stacktraces.test.w | 2 +- libs/wingsdk/src/shared/bundling.ts | 4 ++-- libs/wingsdk/src/shared/sandbox.ts | 4 +++- tools/hangar/__snapshots__/error.ts.snap | 24 +++++++++++++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/examples/tests/error/inflight_stacktraces.test.w b/examples/tests/error/inflight_stacktraces.test.w index 5b94c67c925..0ae2580905d 100644 --- a/examples/tests/error/inflight_stacktraces.test.w +++ b/examples/tests/error/inflight_stacktraces.test.w @@ -20,4 +20,4 @@ test "throw from closure" { throw "ouch"; }; closure(); -} \ No newline at end of file +} diff --git a/libs/wingsdk/src/shared/bundling.ts b/libs/wingsdk/src/shared/bundling.ts index fde8ba216d8..146466c794e 100644 --- a/libs/wingsdk/src/shared/bundling.ts +++ b/libs/wingsdk/src/shared/bundling.ts @@ -72,13 +72,13 @@ export function createBundle( new TextDecoder().decode(esbuild.outputFiles[0].contents) ); if (sourcemapData.sourceRoot) { - sourcemapData.sourceRoot = normalPath(resolve(sourcemapData.sourceRoot)); + sourcemapData.sourceRoot = normalPath(sourcemapData.sourceRoot); } for (const [idx, source] of Object.entries( sourcemapData.sources as string[] )) { - sourcemapData.sources[idx] = normalPath(resolve(source)); + sourcemapData.sources[idx] = normalPath(source); } writeFileSync(outfile, bundleOutput.contents); diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index 86585b7b1f8..64d1c605275 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -110,7 +110,9 @@ process.on("message", async (message) => { const child = cp.fork(this.entrypoint, [], { env: this.options.env, stdio: "pipe", - execArgv: ["--enable-source-maps"], + cwd: process.cwd(), + // execArgv: ["--enable-source-maps"], + // this option allows complex objects like Error to be sent from the child process to the parent serialization: "advanced", }); diff --git a/tools/hangar/__snapshots__/error.ts.snap b/tools/hangar/__snapshots__/error.ts.snap index a7fec3095c0..b50fac72d30 100644 --- a/tools/hangar/__snapshots__/error.ts.snap +++ b/tools/hangar/__snapshots__/error.ts.snap @@ -20,6 +20,12 @@ Duration " exports[`inflight_stacktraces.test.w 1`] = ` "fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert │ Error: assertion failed: false + │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:7:3 + │ | let bucket = new cloud.Bucket(); + │ | + │ | test \\"assert\\" { + │ 7 | assert(false); + │ | ^ │ at /inflight_stacktraces.test.w:7:3 │ at handler /handler_c8b175d2.sandbox.js:18:25 └ at /handler_c8b175d2.sandbox.js:23:19 @@ -28,16 +34,34 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ │ 1 !== 2 │ + │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:11:3 + │ | } + │ | + │ | test \\"expect.equal\\" { + │ 11 | expect.equal(1,2 ); + │ | ^ │ at /inflight_stacktraces.test.w:11:3 │ at handler /handler_c822920b.sandbox.js:19:25 └ at /handler_c822920b.sandbox.js:24:19 fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get │ Error: Object does not exist (key=doesn't exist): Error: ENOENT: no such file or directory, open '../../../examples/tests/error/target/test/inflight_stacktraces.test.wsim/.state/' + │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:15:3 + │ | } + │ | + │ | test \\"bucket failed get\\" { + │ 15 | bucket.get(\\"doesn't exist\\"); + │ | ^ │ at /inflight_stacktraces.test.w:15:3 │ at handler /handler_c894fc5f.sandbox.js:29:10 └ at /handler_c894fc5f.sandbox.js:34:19 fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ Error: ouch + │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:20:5 + │ | + │ | test \\"throw from closure\\" { + │ | let closure = inflight () => { + │ 20 | throw \\"ouch\\"; + │ | ^ │ at closure /inflight_stacktraces.test.w:20:5 │ at /inflight_stacktraces.test.w:22:3 │ at handler /handler_c829ffec.sandbox.js:18:25 From e6a1112267cb4713f205c726ea7480aad7d7af4c Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Wed, 6 Mar 2024 11:57:08 -0500 Subject: [PATCH 20/27] undo example change --- examples/tests/error/inflight_stacktraces.test.w | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tests/error/inflight_stacktraces.test.w b/examples/tests/error/inflight_stacktraces.test.w index 0ae2580905d..5b94c67c925 100644 --- a/examples/tests/error/inflight_stacktraces.test.w +++ b/examples/tests/error/inflight_stacktraces.test.w @@ -20,4 +20,4 @@ test "throw from closure" { throw "ouch"; }; closure(); -} +} \ No newline at end of file From 9134a3076969a1a417d0ed317f9cc9d0c7ec0e72 Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Wed, 6 Mar 2024 17:11:11 +0000 Subject: [PATCH 21/27] chore: self mutation (build.diff) Signed-off-by: monada-bot[bot] --- .../wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap b/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap index 8491a47059a..e875ea04279 100644 --- a/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap +++ b/libs/wingsdk/test/simulator/__snapshots__/simulator.test.ts.snap @@ -93,7 +93,7 @@ exports[`run single test > test failure 1`] = ` { "error": "Error: test failed at Handler.handle ([abs]) - at Object.exports.handler ([abs]) + at exports.handler ([abs]) at process. ([abs]) at process.emit (node:events:) at emit (node:internal/child_process:) From 3a56626012e66316066c5ff3dabbf1c813434671 Mon Sep 17 00:00:00 2001 From: "monada-bot[bot]" Date: Wed, 6 Mar 2024 17:11:12 +0000 Subject: [PATCH 22/27] chore: self mutation (e2e-2of2.diff) Signed-off-by: monada-bot[bot] --- tools/hangar/__snapshots__/error.ts.snap | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/hangar/__snapshots__/error.ts.snap b/tools/hangar/__snapshots__/error.ts.snap index b50fac72d30..5dcbe47754e 100644 --- a/tools/hangar/__snapshots__/error.ts.snap +++ b/tools/hangar/__snapshots__/error.ts.snap @@ -20,7 +20,7 @@ Duration " exports[`inflight_stacktraces.test.w 1`] = ` "fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert │ Error: assertion failed: false - │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:7:3 + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:7:3 │ | let bucket = new cloud.Bucket(); │ | │ | test \\"assert\\" { @@ -34,7 +34,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ │ 1 !== 2 │ - │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:11:3 + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:11:3 │ | } │ | │ | test \\"expect.equal\\" { @@ -45,7 +45,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal └ at /handler_c822920b.sandbox.js:24:19 fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get │ Error: Object does not exist (key=doesn't exist): Error: ENOENT: no such file or directory, open '../../../examples/tests/error/target/test/inflight_stacktraces.test.wsim/.state/' - │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:15:3 + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:15:3 │ | } │ | │ | test \\"bucket failed get\\" { @@ -56,7 +56,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get └ at /handler_c894fc5f.sandbox.js:34:19 fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ Error: ouch - │ --> ../../../../../../../private/Users/chrisr/dev/wing1/examples/tests/error/inflight_stacktraces.test.w:20:5 + │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:20:5 │ | │ | test \\"throw from closure\\" { │ | let closure = inflight () => { From 3e20ff73e4af1c21633ad840f356c15164a3a9a6 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Wed, 6 Mar 2024 12:27:00 -0500 Subject: [PATCH 23/27] try to stop redis more gracefully? --- libs/wingsdk/src/target-sim/redis.inflight.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/wingsdk/src/target-sim/redis.inflight.ts b/libs/wingsdk/src/target-sim/redis.inflight.ts index 4519198984a..fe06cc1b349 100644 --- a/libs/wingsdk/src/target-sim/redis.inflight.ts +++ b/libs/wingsdk/src/target-sim/redis.inflight.ts @@ -58,6 +58,7 @@ export class Redis public async cleanup(): Promise { this.isCleanedUp = true; // disconnect from the redis server + await this.connection?.quit(); this.connection?.disconnect(); // stop the redis container await runCommand("docker", ["rm", "-f", this.containerName]); From 509b6d203a907224b5d7c6dfad3a4df70fa88351 Mon Sep 17 00:00:00 2001 From: Mark McCulloh Date: Wed, 6 Mar 2024 12:57:49 -0500 Subject: [PATCH 24/27] fix bad symlinks for bundled inflights --- libs/wingsdk/src/shared/bundling.ts | 11 +++++++---- libs/wingsdk/src/shared/sandbox.ts | 1 - 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/wingsdk/src/shared/bundling.ts b/libs/wingsdk/src/shared/bundling.ts index 146466c794e..054745ce856 100644 --- a/libs/wingsdk/src/shared/bundling.ts +++ b/libs/wingsdk/src/shared/bundling.ts @@ -1,6 +1,6 @@ import * as crypto from "crypto"; -import { mkdirSync, writeFileSync } from "fs"; -import { join, resolve } from "path"; +import { mkdirSync, realpathSync, writeFileSync } from "fs"; +import { join, resolve } from "path/posix"; import { normalPath } from "./misc"; const SDK_PATH = normalPath(resolve(__dirname, "..", "..")); @@ -25,7 +25,10 @@ export function createBundle( external: string[] = [], outputDir?: string ): Bundle { - const outdir = resolve(outputDir ?? entrypoint + ".bundle"); + const normalEntrypoint = normalPath(realpathSync(entrypoint)); + const outdir = outputDir + ? normalPath(realpathSync(outputDir)) + : `${normalEntrypoint}.bundle`; mkdirSync(outdir, { recursive: true }); const outfileName = "index.js"; @@ -39,7 +42,7 @@ export function createBundle( let esbuild = esbuilder.buildSync({ bundle: true, - entryPoints: [normalPath(resolve(entrypoint))], + entryPoints: [normalEntrypoint], outfile, // otherwise there are problems with running azure cloud functions: // https://stackoverflow.com/questions/70332883/webpack-azure-storage-blob-node-fetch-abortsignal-issue diff --git a/libs/wingsdk/src/shared/sandbox.ts b/libs/wingsdk/src/shared/sandbox.ts index 64d1c605275..9d065bfc91a 100644 --- a/libs/wingsdk/src/shared/sandbox.ts +++ b/libs/wingsdk/src/shared/sandbox.ts @@ -110,7 +110,6 @@ process.on("message", async (message) => { const child = cp.fork(this.entrypoint, [], { env: this.options.env, stdio: "pipe", - cwd: process.cwd(), // execArgv: ["--enable-source-maps"], // this option allows complex objects like Error to be sent from the child process to the parent serialization: "advanced", From 0a7bcc16dc17e32351ccead43515dcadbbdf4f3e Mon Sep 17 00:00:00 2001 From: Mark McCulloh Date: Wed, 6 Mar 2024 13:10:05 -0500 Subject: [PATCH 25/27] sourcemap fix broke windows, switch to regular resolve() --- libs/wingsdk/src/shared/bundling.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/wingsdk/src/shared/bundling.ts b/libs/wingsdk/src/shared/bundling.ts index 054745ce856..e8ffbba8b50 100644 --- a/libs/wingsdk/src/shared/bundling.ts +++ b/libs/wingsdk/src/shared/bundling.ts @@ -1,6 +1,6 @@ import * as crypto from "crypto"; import { mkdirSync, realpathSync, writeFileSync } from "fs"; -import { join, resolve } from "path/posix"; +import { posix, resolve } from "path"; import { normalPath } from "./misc"; const SDK_PATH = normalPath(resolve(__dirname, "..", "..")); @@ -34,8 +34,8 @@ export function createBundle( const outfileName = "index.js"; const soucemapFilename = `${outfileName}.map`; - const outfile = join(outdir, outfileName); - const outfileMap = join(outdir, soucemapFilename); + const outfile = posix.join(outdir, outfileName); + const outfileMap = posix.join(outdir, soucemapFilename); // eslint-disable-next-line import/no-extraneous-dependencies,@typescript-eslint/no-require-imports const esbuilder: typeof import("esbuild") = require("esbuild"); From 89fd5749e3e5bb90ba8d8150c879bc82b032adbc Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Wed, 6 Mar 2024 15:33:38 -0500 Subject: [PATCH 26/27] filter out sandbox paths --- libs/wingsdk/src/util/enhanced-error.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/wingsdk/src/util/enhanced-error.ts b/libs/wingsdk/src/util/enhanced-error.ts index 4591918a351..e3dbe7a37ca 100644 --- a/libs/wingsdk/src/util/enhanced-error.ts +++ b/libs/wingsdk/src/util/enhanced-error.ts @@ -78,7 +78,10 @@ export async function prettyPrintError( !normalPath(item.file).includes("/@winglang/sdk/") ) // special: remove the handler wrapper (See `cloud.Function` entrypoint for where this comes from) - .filter((item) => !normalPath(item.file).match(/\.wing\/handler_\w+\.js$/)) + .filter( + (item) => + !normalPath(item.file).match(/\.wing\/handler_\w+(\.sandbox)?\.js$/) + ) .withSourcesAsync(); let traceWithSources = st.items; From 20bb702193f221780099e1730b6497b4522df8ae Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Wed, 6 Mar 2024 15:34:11 -0500 Subject: [PATCH 27/27] update snap --- tools/hangar/__snapshots__/error.ts.snap | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/tools/hangar/__snapshots__/error.ts.snap b/tools/hangar/__snapshots__/error.ts.snap index 5dcbe47754e..8ffaed3182b 100644 --- a/tools/hangar/__snapshots__/error.ts.snap +++ b/tools/hangar/__snapshots__/error.ts.snap @@ -26,9 +26,7 @@ exports[`inflight_stacktraces.test.w 1`] = ` │ | test \\"assert\\" { │ 7 | assert(false); │ | ^ - │ at /inflight_stacktraces.test.w:7:3 - │ at handler /handler_c8b175d2.sandbox.js:18:25 - └ at /handler_c8b175d2.sandbox.js:23:19 + └ at /inflight_stacktraces.test.w:7:3 fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ Error: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: │ @@ -40,9 +38,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ | test \\"expect.equal\\" { │ 11 | expect.equal(1,2 ); │ | ^ - │ at /inflight_stacktraces.test.w:11:3 - │ at handler /handler_c822920b.sandbox.js:19:25 - └ at /handler_c822920b.sandbox.js:24:19 + └ at /inflight_stacktraces.test.w:11:3 fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get │ Error: Object does not exist (key=doesn't exist): Error: ENOENT: no such file or directory, open '../../../examples/tests/error/target/test/inflight_stacktraces.test.wsim/.state/' │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:15:3 @@ -51,9 +47,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed get │ | test \\"bucket failed get\\" { │ 15 | bucket.get(\\"doesn't exist\\"); │ | ^ - │ at /inflight_stacktraces.test.w:15:3 - │ at handler /handler_c894fc5f.sandbox.js:29:10 - └ at /handler_c894fc5f.sandbox.js:34:19 + └ at /inflight_stacktraces.test.w:15:3 fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ Error: ouch │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:20:5 @@ -63,9 +57,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ 20 | throw \\"ouch\\"; │ | ^ │ at closure /inflight_stacktraces.test.w:20:5 - │ at /inflight_stacktraces.test.w:22:3 - │ at handler /handler_c829ffec.sandbox.js:18:25 - └ at /handler_c829ffec.sandbox.js:23:19 + └ at /inflight_stacktraces.test.w:22:3 Tests 4 failed (4)