Skip to content

Commit 9352af4

Browse files
committed
Clean typed test boundary assertions
1 parent b039b6e commit 9352af4

3 files changed

Lines changed: 37 additions & 28 deletions

File tree

packages/core/sdk/src/promise.test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,24 +102,21 @@ describe("promise/createExecutor", () => {
102102
const ran = await executor.tools.invoke("ap.ctl.go", {});
103103
expect(ran).toBe("ran");
104104

105-
// Override with a declining handler → rejects with ElicitationDeclinedError.
106-
// Effect.runPromise rejects with a FiberFailure that wraps the typed
107-
// error; both `name` and `message` carry the tag.
108-
let caught: unknown;
109-
try {
110-
await executor.tools.invoke(
105+
// Override with a declining handler -> rejects with ElicitationDeclinedError.
106+
// Effect.runPromise rejects with a FiberFailure that carries the tag in
107+
// the error name.
108+
await expect(
109+
executor.tools.invoke(
111110
"ap.ctl.go",
112111
{},
113112
{
114113
onElicitation: () =>
115114
Effect.succeed({ action: "decline" as const }) as any,
116115
},
117-
);
118-
} catch (e) {
119-
caught = e;
120-
}
121-
expect(caught).toBeDefined();
122-
expect((caught as Error).name).toMatch(/ElicitationDeclinedError/);
116+
),
117+
).rejects.toMatchObject({
118+
name: expect.stringMatching(/ElicitationDeclinedError/),
119+
});
123120

124121
await executor.close();
125122
});

packages/core/sdk/src/scoped-adapter.test.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ describe("scopeAdapter — write rejection on scoped tables", () => {
4545
const reason = result.cause.reasons.find(Cause.isFailReason);
4646
const err = reason?.error ?? null;
4747
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+
);
4953
}),
5054
);
5155

@@ -70,7 +74,11 @@ describe("scopeAdapter — write rejection on scoped tables", () => {
7074
const reason = result.cause.reasons.find(Cause.isFailReason);
7175
const err = reason?.error ?? null;
7276
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+
);
7482
}),
7583
);
7684

tests/daemon-bootstrap.test.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,26 +116,30 @@ describe("daemon bootstrap helpers", () => {
116116

117117
it("falls back when preferred daemon port is occupied", async () => {
118118
const blocker = createServer();
119-
await new Promise<void>((resolve, reject) => {
120-
blocker.once("error", reject);
121-
blocker.listen({ port: 0, host: "127.0.0.1" }, () => resolve());
122-
});
119+
await Effect.runPromise(Effect.scoped(Effect.gen(function*() {
120+
yield* Effect.acquireRelease(
121+
Effect.callback<void, Error>((resume) => {
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+
);
123130

124-
const occupied = (() => {
125-
const address = blocker.address();
126-
return typeof address === "object" && address !== null ? address.port : 0;
127-
})();
131+
const occupied = (() => {
132+
const address = blocker.address();
133+
return typeof address === "object" && address !== null ? address.port : 0;
134+
})();
128135

129-
try {
130-
const picked = await Effect.runPromise(
136+
const picked = yield* (
131137
chooseDaemonPort({
132138
preferredPort: occupied,
133139
hostname: "127.0.0.1",
134-
}),
140+
})
135141
);
136142
expect(picked).not.toBe(occupied);
137-
} finally {
138-
await new Promise<void>((resolve) => blocker.close(() => resolve()));
139-
}
143+
})));
140144
});
141145
});

0 commit comments

Comments
 (0)