From fa4a7a5080bfedb3e85c015f1e7c0ee6468eafb0 Mon Sep 17 00:00:00 2001 From: Chris Rybicki Date: Mon, 22 Apr 2024 16:19:35 -0400 Subject: [PATCH] fix(sdk): store simulator paths as absolute path (#6299) Normalize the code within the SDK so that the paths to various simulator files are stored as absolute paths. This is causing an issue where the feature added in https://github.com/winglang/wing/pull/6295 only works when running `wing it` and not in `wing test` because `wing test` initializes the simulator with a relative path. ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [ ] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*. --- .../tests/error/inflight_stacktraces.test.w | 4 ++-- libs/wingsdk/src/simulator/simulator.ts | 8 +++---- tools/hangar/__snapshots__/error.ts.snap | 24 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/tests/error/inflight_stacktraces.test.w b/examples/tests/error/inflight_stacktraces.test.w index 03dfd66fa5b..3a676411ee9 100644 --- a/examples/tests/error/inflight_stacktraces.test.w +++ b/examples/tests/error/inflight_stacktraces.test.w @@ -11,8 +11,8 @@ test "expect.equal" { expect.equal(1,2 ); } -test "bucket failed get" { - bucket.get("doesn't exist"); +test "bucket failed delete" { + bucket.delete("doesn't exist", mustExist: true); } test "throw from closure" { diff --git a/libs/wingsdk/src/simulator/simulator.ts b/libs/wingsdk/src/simulator/simulator.ts index 0cac0f7937c..ccec2885b15 100644 --- a/libs/wingsdk/src/simulator/simulator.ts +++ b/libs/wingsdk/src/simulator/simulator.ts @@ -1,7 +1,7 @@ import { existsSync } from "fs"; import { mkdir, rm } from "fs/promises"; import type { Server, IncomingMessage, ServerResponse } from "http"; -import { join } from "path"; +import { join, resolve } from "path"; import { makeSimulatorClient } from "./client"; import { Graph } from "./graph"; import { deserialize, serialize } from "./serialization"; @@ -208,7 +208,7 @@ export class Simulator { private state: Record = {}; constructor(props: SimulatorProps) { - const simdir = props.simfile; + const simdir = resolve(props.simfile); this.statedir = props.stateDir ?? join(simdir, ".state"); this._model = this._loadApp(simdir); @@ -731,14 +731,14 @@ export class Simulator { // start the server, and wait for it to be listening const server = http.createServer(requestListener); - await new Promise((resolve) => { + await new Promise((ok) => { server.listen(0, LOCALHOST_ADDRESS, () => { const addr = server.address(); if (addr && typeof addr === "object" && (addr as any).port) { this._serverUrl = `http://${addr.address}:${addr.port}`; } this._server = server; - resolve(); + ok(); }); }); } diff --git a/tools/hangar/__snapshots__/error.ts.snap b/tools/hangar/__snapshots__/error.ts.snap index 93b2022a29f..757920a5432 100644 --- a/tools/hangar/__snapshots__/error.ts.snap +++ b/tools/hangar/__snapshots__/error.ts.snap @@ -37,13 +37,13 @@ at /inflight_stacktraces.test.w:7:3 11 | expect.equal(1,2 ); | ^ at /inflight_stacktraces.test.w:11:3 -[ERROR] bucket failed get | Get (key=doesn't exist). 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/' -[ERROR] bucket failed get | Invoke (payload=undefined). 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/' +[ERROR] bucket failed delete | Delete (key=doesn't exist). Error: Object does not exist (key=doesn't exist). +[ERROR] bucket failed delete | Invoke (payload=undefined). Error: Object does not exist (key=doesn't exist). --> ../../../examples/tests/error/inflight_stacktraces.test.w:15:3 | } | - | test \\"bucket failed get\\" { -15 | bucket.get(\\"doesn't exist\\"); + | test \\"bucket failed delete\\" { +15 | bucket.delete(\\"doesn't exist\\", mustExist: true); | ^ at /inflight_stacktraces.test.w:15:3 [ERROR] throw from closure | Invoke (payload=undefined). Error: ouch @@ -63,7 +63,7 @@ at /inflight_stacktraces.test.w:22:3 27 | assert(x, \\"x is false\\"); | ^ at /inflight_stacktraces.test.w:27:3 -fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert +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(); @@ -72,7 +72,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert │ 7 | assert(false); │ | ^ └ at /inflight_stacktraces.test.w:7:3 -fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal +fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ Error: AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal: │ │ 1 !== 2 @@ -84,16 +84,16 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal │ 11 | expect.equal(1,2 ); │ | ^ └ 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/' +fail ┌ inflight_stacktraces.test.wsim » root/env2/test:bucket failed delete + │ Error: Object does not exist (key=doesn't exist). │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:15:3 │ | } │ | - │ | test \\"bucket failed get\\" { - │ 15 | bucket.get(\\"doesn't exist\\"); + │ | test \\"bucket failed delete\\" { + │ 15 | bucket.delete(\\"doesn't exist\\", mustExist: true); │ | ^ └ at /inflight_stacktraces.test.w:15:3 -fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure +fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ Error: ouch │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:20:5 │ | @@ -103,7 +103,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure │ | ^ │ at closure /inflight_stacktraces.test.w:20:5 └ at /inflight_stacktraces.test.w:22:3 -fail ┌ inflight_stacktraces.test.wsim » root/env4/test:assert with message +fail ┌ inflight_stacktraces.test.wsim » root/env4/test:assert with message │ Error: assertion failed: x is false │ --> ../../../examples/tests/error/inflight_stacktraces.test.w:27:3 │ |