Skip to content

Commit 8f51ef1

Browse files
committed
test(webapp): restore PAT action type guard
1 parent e0800f1 commit 8f51ef1

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { json } from "@remix-run/server-runtime";
2+
import { z } from "zod";
3+
import {
4+
createActionPATApiRoute,
5+
createLoaderPATApiRoute,
6+
} from "~/services/routeBuilders/apiBuilder.server";
7+
8+
// A type-level test, not a runtime one: `.test.ts` is excluded from `tsconfig.check.json`, so this
9+
// file is named `.types.ts` to be checked by `pnpm run typecheck --filter webapp`.
10+
//
11+
// `identityOnly` waives the refusal an environment-scoped user-actor token gets on a route that
12+
// names nothing to check its claim against. It is only sound for reads, so the action builder must
13+
// not accept it.
14+
15+
export const identityOnlyLoader = createLoaderPATApiRoute({ identityOnly: true }, async () =>
16+
json({ ok: true })
17+
);
18+
19+
export const identityOnlyAction = createActionPATApiRoute(
20+
{
21+
method: "POST",
22+
params: z.object({ id: z.string() }),
23+
// @ts-expect-error — an action mutates, so it can never be identity-only.
24+
identityOnly: true,
25+
},
26+
async () => json({ ok: true })
27+
);

knip.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"prisma/populate.ts",
1919
"scripts/**/*.{js,mjs,cjs,ts,mts,cts}",
2020
"test/**/*.producer.ts",
21+
"test/types/**/*.types.ts",
2122
"test/setup/global-e2e-full-setup.ts",
2223
"vite/node-globals-shim.js",
2324
"app/v3/otlpTransformWorker.ts"

0 commit comments

Comments
 (0)