fix: close competition cutover integrity gaps

This commit is contained in:
dahyeon committed 2026-07-12 21:22:22 +00:00
1 parent 7ea2002975
commit 683d602d63
57 files changed
+4805 -1582

No files matched your search

+108
View File
@@ -0,0 +1,108 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
executeAuthScopedQuery,
resolveAuthQueryScope,
} from "../src/api/auth-query-scope.ts";
test("waits for MSAL before an anonymous optional-auth query starts", () => {
const scope = resolveAuthQueryScope({
authUserId: null,
accountKey: null,
msalConfigured: true,
msalReady: false,
});
assert.equal(scope.ready, false);
assert.deepEqual(scope.cacheKey, [null, null]);
});
test("allows an anonymous query once MSAL initialization finishes", () => {
const scope = resolveAuthQueryScope({
authUserId: null,
accountKey: null,
msalConfigured: true,
msalReady: true,
});
assert.equal(scope.ready, true);
});
test("allows dev auth during MSAL startup and scopes its cache by user", () => {
const first = resolveAuthQueryScope({
authUserId: "dev-user-1",
accountKey: null,
msalConfigured: true,
msalReady: false,
});
const second = resolveAuthQueryScope({
authUserId: "dev-user-2",
accountKey: null,
msalConfigured: true,
msalReady: false,
});
assert.equal(first.ready, true);
assert.notDeepEqual(first.cacheKey, second.cacheKey);
});
test("separates optional-auth query caches by MSAL account", () => {
const first = resolveAuthQueryScope({
authUserId: null,
accountKey: "account-1",
msalConfigured: true,
msalReady: true,
});
const second = resolveAuthQueryScope({
authUserId: null,
accountKey: "account-2",
msalConfigured: true,
msalReady: true,
});
assert.notDeepEqual(first.cacheKey, second.cacheKey);
});
test("keeps the existing dev or anonymous request path when no account exists", async () => {
let tokenAcquisitions = 0;
const result = await executeAuthScopedQuery({
accountKey: null,
acquireAccessToken: () => {
tokenAcquisitions += 1;
return Promise.resolve("unused-token");
},
request: (authorizationHeader) =>
Promise.resolve(authorizationHeader ?? "dev-or-anonymous"),
});
assert.equal(result, "dev-or-anonymous");
assert.equal(tokenAcquisitions, 0);
});
test("does not run an anonymous request when account token acquisition fails", async () => {
let requests = 0;
await assert.rejects(
executeAuthScopedQuery({
accountKey: "account-1",
acquireAccessToken: () => Promise.reject(new Error("token failed")),
request: () => {
requests += 1;
return Promise.resolve("must-not-run");
},
}),
/token failed/,
);
assert.equal(requests, 0);
});
test("sends an explicit bearer token for an authenticated account", async () => {
const authorizationHeader = await executeAuthScopedQuery({
accountKey: "account-1",
acquireAccessToken: () => Promise.resolve("access-token"),
request: (header) => Promise.resolve(header),
});
assert.equal(authorizationHeader, "Bearer access-token");
});
@@ -0,0 +1,57 @@
import assert from "node:assert/strict";
import test from "node:test";
import {
getTeamProgressErrorContent,
isConsistentTeamProgressSnapshot,
} from "../src/pages/match-team-progress-state.ts";
test("only accepts Competition and team snapshots with the same revision", () => {
assert.equal(
isConsistentTeamProgressSnapshot({ revision: 7 }, { revision: 7 }),
true,
);
assert.equal(
isConsistentTeamProgressSnapshot({ revision: 7 }, { revision: 8 }),
false,
);
assert.equal(isConsistentTeamProgressSnapshot(undefined, { revision: 7 }), false);
});
test("describes a 401 response as an authentication error", () => {
assert.equal(
getTeamProgressErrorContent([{ status: 401 }]).kind,
"unauthorized",
);
});
test("describes a 403 response as a team access error", () => {
assert.equal(
getTeamProgressErrorContent([{ status: 403 }]).kind,
"forbidden",
);
});
test("describes a 404 response as missing Competition data", () => {
assert.equal(getTeamProgressErrorContent([{ status: 404 }]).kind, "not-found");
});
test("describes a 5xx response as a server error", () => {
assert.equal(getTeamProgressErrorContent([{ status: 503 }]).kind, "server");
});
test("describes a failed fetch as a network error", () => {
assert.equal(
getTeamProgressErrorContent([new TypeError("Failed to fetch")]).kind,
"network",
);
});
test("prioritizes authentication and authorization errors from either query", () => {
assert.equal(
getTeamProgressErrorContent([
new TypeError("Failed to fetch"),
{ status: 403 },
]).kind,
"forbidden",
);
});