History

Clean typed test boundary assertions

Rhys Sullivan committed 6 months ago

Commit 9352af41 parent b039b6e3 files · +37 −28Browse files

Unified · Split

3 files
  1. packages/core/sdk/src/promise.test.ts +9 −12
  2. packages/core/sdk/src/scoped-adapter.test.ts +10 −2
  3. tests/daemon-bootstrap.test.ts +18 −14
packages/core/sdk/src/promise.test.ts+9−12
@@ -102,24 +102,21 @@ describe("promise/createExecutor", () => { · 101 unmodified lines
102 const ran = await executor.tools.invoke("ap.ctl.go", {});102 const ran = await executor.tools.invoke("ap.ctl.go", {});
103 expect(ran).toBe("ran");103 expect(ran).toBe("ran");
104 104
105 // Override with a declining handler → rejects with ElicitationDeclinedError.105 // Override with a declining handler -> rejects with ElicitationDeclinedError.
106 // Effect.runPromise rejects with a FiberFailure that wraps the typed106 // Effect.runPromise rejects with a FiberFailure that carries the tag in
107 // error; both `name` and `message` carry the tag.107 // the error name.
108 let caught: unknown;108 await expect(
109 try {109 executor.tools.invoke(
110 await executor.tools.invoke(
111 "ap.ctl.go",110 "ap.ctl.go",
112 {},111 {},
113 {112 {
114 onElicitation: () =>113 onElicitation: () =>
115 Effect.succeed({ action: "decline" as const }) as any,114 Effect.succeed({ action: "decline" as const }) as any,
116 },115 },
117 );116 ),
118 } catch (e) {117 ).rejects.toMatchObject({
119 caught = e;118 name: expect.stringMatching(/ElicitationDeclinedError/),
120 }119 });
121 expect(caught).toBeDefined();
122 expect((caught as Error).name).toMatch(/ElicitationDeclinedError/);
123 120
124 await executor.close();121 await executor.close();
125 });122 });
packages/core/sdk/src/scoped-adapter.test.ts+10−2
@@ -45,7 +45,11 @@ describe("scopeAdapter — write rejection on scoped tables", () => { · 44 unmodified lines
45 const reason = result.cause.reasons.find(Cause.isFailReason);45 const reason = result.cause.reasons.find(Cause.isFailReason);
46 const err = reason?.error ?? null;46 const err = reason?.error ?? null;
47 expect(err).toBeInstanceOf(StorageError);47 expect(err).toBeInstanceOf(StorageError);
48 expect((err as StorageError).message).toContain("not in the executor");48 expect(err).toEqual(
49 expect.objectContaining({
50 message: expect.stringContaining("not in the executor"),
51 }),
52 );
49 }),53 }),
50 );54 );
51 55
@@ -70,7 +74,11 @@ describe("scopeAdapter — write rejection on scoped tables", () => { · 18 unmodified lines
70 const reason = result.cause.reasons.find(Cause.isFailReason);74 const reason = result.cause.reasons.find(Cause.isFailReason);
71 const err = reason?.error ?? null;75 const err = reason?.error ?? null;
72 expect(err).toBeInstanceOf(StorageError);76 expect(err).toBeInstanceOf(StorageError);
73 expect((err as StorageError).message).toContain("missing required");77 expect(err).toEqual(
78 expect.objectContaining({
79 message: expect.stringContaining("missing required"),
80 }),
81 );
74 }),82 }),
75 );83 );
76 84
tests/daemon-bootstrap.test.ts+18−14
@@ -116,26 +116,30 @@ describe("daemon bootstrap helpers", () => { · 115 unmodified lines
116 116
117 it("falls back when preferred daemon port is occupied", async () => {117 it("falls back when preferred daemon port is occupied", async () => {
118 const blocker = createServer();118 const blocker = createServer();
119 await new Promise<void>((resolve, reject) => {119 await Effect.runPromise(Effect.scoped(Effect.gen(function*() {
120 blocker.once("error", reject);120 yield* Effect.acquireRelease(
121 blocker.listen({ port: 0, host: "127.0.0.1" }, () => resolve());121 Effect.callback<void, Error>((resume) => {
122 });122 blocker.once("error", (error) => resume(Effect.fail(error)));
123 blocker.listen({ port: 0, host: "127.0.0.1" }, () =>
124 resume(Effect.succeed(undefined)));
125 }),
126 () => Effect.promise(() => new Promise<void>((resolve) => {
127 blocker.close(() => resolve());
128 })),
129 );
123 130
124 const occupied = (() => {131 const occupied = (() => {
125 const address = blocker.address();132 const address = blocker.address();
126 return typeof address === "object" && address !== null ? address.port : 0;133 return typeof address === "object" && address !== null ? address.port : 0;
127 })();134 })();
128 135
129 try {136 const picked = yield* (
130 const picked = await Effect.runPromise(
131 chooseDaemonPort({137 chooseDaemonPort({
132 preferredPort: occupied,138 preferredPort: occupied,
133 hostname: "127.0.0.1",139 hostname: "127.0.0.1",
134 }),140 })
135 );141 );
136 expect(picked).not.toBe(occupied);142 expect(picked).not.toBe(occupied);
137 } finally {143 })));
138 await new Promise<void>((resolve) => blocker.close(() => resolve()));
139 }
140 });144 });
141});145});