Skip to content

Commit

Permalink
fix(sdk): store simulator paths as absolute path (#6299)
Browse files Browse the repository at this point in the history
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 #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)*.
  • Loading branch information
Chriscbr committed Apr 22, 2024
1 parent 7fad94a commit fa4a7a5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions examples/tests/error/inflight_stacktraces.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
8 changes: 4 additions & 4 deletions libs/wingsdk/src/simulator/simulator.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -208,7 +208,7 @@ export class Simulator {
private state: Record<string, ResourceState> = {};

constructor(props: SimulatorProps) {
const simdir = props.simfile;
const simdir = resolve(props.simfile);
this.statedir = props.stateDir ?? join(simdir, ".state");
this._model = this._loadApp(simdir);

Expand Down Expand Up @@ -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<void>((resolve) => {
await new Promise<void>((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();
});
});
}
Expand Down
24 changes: 12 additions & 12 deletions tools/hangar/__snapshots__/error.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ at <ABSOLUTE>/inflight_stacktraces.test.w:7:3
11 | expect.equal(1,2 );
| ^
at <ABSOLUTE>/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/<STATE_FILE>'
[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/<STATE_FILE>'
[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 <ABSOLUTE>/inflight_stacktraces.test.w:15:3
[ERROR] throw from closure | Invoke (payload=undefined). Error: ouch
Expand All @@ -63,7 +63,7 @@ at <ABSOLUTE>/inflight_stacktraces.test.w:22:3
27 | assert(x, \\"x is false\\");
| ^
at <ABSOLUTE>/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();
Expand All @@ -72,7 +72,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env0/test:assert
7 | assert(false);
| ^
at <ABSOLUTE>/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
Expand All @@ -84,16 +84,16 @@ fail ┌ inflight_stacktraces.test.wsim » root/env1/test:expect.equal
11 | expect.equal(1,2 );
| ^
at <ABSOLUTE>/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/<STATE_FILE>'
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 <ABSOLUTE>/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
│ |
Expand All @@ -103,7 +103,7 @@ fail ┌ inflight_stacktraces.test.wsim » root/env3/test:throw from closure
| ^
at closure <ABSOLUTE>/inflight_stacktraces.test.w:20:5
└ at <ABSOLUTE>/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
│ |
Expand Down

0 comments on commit fa4a7a5

Please sign in to comment.