fix: align bound query keys with invalidation prefixes

This commit is contained in:
DongHyeonka
2026-08-01 22:11:04 +09:00
parent 92c3d438ab
commit 853c2e3f30
4 changed files with 207 additions and 8 deletions
+37 -1
View File
@@ -20,7 +20,11 @@ import {
type QueryInvalidationCoordinator,
} from "../../src/contracts/query-invalidation.ts";
import { createFailure } from "../../src/contracts/errors.ts";
import { createRuntimeIdentityRegistry } from "../../src/contracts/query-keys.ts";
import {
createQueryInvalidationPrefix,
createRuntimeIdentityRegistry,
defineQueryNamespaceIdentity,
} from "../../src/contracts/query-keys.ts";
import {
bindQuery,
type QueryResultMeasure,
@@ -216,6 +220,38 @@ describe("application query inbound bridge", () => {
});
describe("scope-bound query commit fence", () => {
it("binds the namespace-first V2 query key", () => {
const scope = scopeSnapshot();
const definition = {
definitionId: "reference-detail-v1",
definitionVersion: 1,
owner: "platform-test",
namespace: "reference-resource",
namespaceVersion: 1,
operationId: "GET_REFERENCE_RESOURCE",
profileId: "DETAIL_STANDARD" as const,
measureResult: measureOne,
execute: async () => ({ ok: true as const, value: "value" }),
};
const bound = bindQuery(definition, "resource-1", scope);
expect(bound.queryKey).toEqual([
"query",
2,
"reference-resource",
1,
"scope-fingerprint-0001",
1,
"scope-identity-token-0001",
]);
expect(bound.queryKey.slice(0, 4)).toEqual(
createQueryInvalidationPrefix(
defineQueryNamespaceIdentity("reference-resource", 1),
),
);
});
it("discards a successful result whose scope was fenced during execution", async () => {
const client = queryClient();
const scope = scopeSnapshot();