History

Type the platform-view write-refusal helper against surface error unions

Rhys Sullivan committed 3 months ago

Commit 7f3cf091 parent f1d58ba1 file · +9 −6Browse files

Unified · Split

packages/core/sdk/src/platform-view.test.ts+9−6
@@ -406,17 +406,20 @@ describe("platform view — admin.listSubjects", () => { · 405 unmodified lines
406 * missing credential provider), and such a failure would let the assertion pass406 * missing credential provider), and such a failure would let the assertion pass
407 * without the policy ever having been consulted.407 * without the policy ever having been consulted.
408 */408 */
409const expectWriteRefused = <A, E extends { readonly _tag: string }>(effect: Effect.Effect<A, E>) =>409const expectWriteRefused = <A, E extends { readonly _tag: string }>(
410 effect.pipe(410 effect: Effect.Effect<A, E | StorageError>,
411 // A write that SUCCEEDS dies here rather than reaching an assertion, so the411) =>
412 // hole this pins can never be reported as a pass.412 // The surfaces under test fail with different unions (StorageFailure,
413 // ConnectionNotFoundError, …). The refusal this pins is always a
414 // StorageError, so the effect is widened for the catch; `orDie` below still
415 // turns every OTHER tag into a test failure, and a write that SUCCEEDS dies
416 // rather than reaching an assertion — so the hole can never pass silently.
417 (effect as Effect.Effect<A, StorageError>).pipe(
413 Effect.flatMap(() => Effect.die("expected the platform view to refuse this write")),418 Effect.flatMap(() => Effect.die("expected the platform view to refuse this write")),
414 Effect.catchTag("StorageError", (error: StorageError) => {419 Effect.catchTag("StorageError", (error: StorageError) => {
415 expect(error.message).toContain("read-only");420 expect(error.message).toContain("read-only");
416 return Effect.void;421 return Effect.void;
417 }),422 }),
418 // Any OTHER failure means the call never reached the owner policy — an
419 // absent row, a missing provider — which would leave the refusal untested.
420 Effect.orDie,423 Effect.orDie,
421 );424 );
422 425