문제: 샘플 제거 드릴(test:sample-removal)이 reference feature를 지우면 설치된 기능이 0개가 된다. 15-01 이후 그 상태에서 기능 기여 타입이 never가 되어 installed-feature-adapters.ts와 테스트 2개가 타입 검사에서 실패했다. features.load는 기능 테스트로만 검증되고 있어서, 기능 테스트가 같이 지워지면 create-application.ts 커버리지가 90% 아래로 떨어졌다. 드릴 사본에 README.md·CHANGELOG.md가 없어 문서 테스트 2개도 실패했다. 방법: never일 때도 통과하는 넓은 타입으로 받아서 읽는다(as 단언 없이 대입). features.load는 가짜 로더로 플랫폼 테스트를 추가했다(한 번만 적재, 남의 input 거부, 실패 후 재시도). 문서 테스트 2개는 드릴 제외 목록에 넣었다. 드릴 사본에 문서를 복사하는 안은 버렸다. 기능 제거와 무관한 파일이 사본 목록에 들어간다. 위험: 넓힌 타입은 기여 타입이 바뀌어도 featureId 검사 부분은 잡지 못한다. 그 검사는 실행 시 TypeError로 남아 있다. 검증: tsc -p tsconfig.test.json 통과, check:types 통과, 관련 단위 테스트 20/20 통과. 드릴은 고치기 전 실행에서 coverage PASS를 확인했고 타입 오류 2건이 남아 있었다. 그 2건을 고친 뒤 드릴 전체는 다시 돌리지 않았다.
210 lines
7.1 KiB
TypeScript
210 lines
7.1 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import {
|
|
createApplication,
|
|
type ApplicationOutputPorts,
|
|
} from "../../src/application/create-application.ts";
|
|
import { createTestApplication } from "../helpers/create-test-application.ts";
|
|
import { createProductFeaturesStub, createRuntimeCapabilitiesStub } from "../helpers/runtime-capabilities-stub.ts";
|
|
|
|
declare module "../../src/application/ports/in/application-api.ts" {
|
|
interface ApplicationFeatureInputs {
|
|
"test-feature": Readonly<{
|
|
run(): "ok";
|
|
}>;
|
|
}
|
|
}
|
|
|
|
describe("application input/output boundary", () => {
|
|
it("exposes intent-oriented input APIs without leaking output ports", async () => {
|
|
const application = createTestApplication();
|
|
|
|
expect(Object.keys(application)).toEqual([
|
|
"session",
|
|
"preferences",
|
|
"diagnostics",
|
|
"runtime",
|
|
"recovery",
|
|
"features",
|
|
]);
|
|
expect(application).not.toHaveProperty("storage");
|
|
expect(application).not.toHaveProperty("telemetry");
|
|
expect(application).not.toHaveProperty("releaseInfo");
|
|
expect(application.features.has("not-installed")).toBe(false);
|
|
expect(() =>
|
|
Reflect.apply(application.features.get, application.features, [
|
|
"not-installed",
|
|
]),
|
|
).toThrow("Application feature is not installed");
|
|
await expect(application.runtime.getReleaseSummary()).resolves.toEqual({
|
|
buildId: "test-build",
|
|
releaseId: "test-release",
|
|
configSchemaVersion: "1",
|
|
apiContractVersion: "1",
|
|
});
|
|
});
|
|
|
|
it("returns a typed input for an installed generic feature", () => {
|
|
const featureInput = Object.freeze({
|
|
run: () => "ok" as const,
|
|
});
|
|
const application = createTestApplication({
|
|
featureInputs: { "test-feature": featureInput },
|
|
});
|
|
|
|
expect(application.features.has("test-feature")).toBe(true);
|
|
expect(application.features.get("test-feature")).toBe(featureInput);
|
|
expect(application.features.get("test-feature").run()).toBe("ok");
|
|
});
|
|
|
|
// 15-01. The reference feature's tests also exercise `features.load`, but
|
|
// they go with the feature (test:sample-removal), so the platform keeps its
|
|
// own check with fake loaders.
|
|
it("loads a feature input once, rejects a foreign one and retries a failed load", async () => {
|
|
const featureInput = Object.freeze({ run: () => "ok" as const });
|
|
const loader = vi
|
|
.fn<() => Promise<Readonly<Record<string, unknown>>>>()
|
|
.mockRejectedValueOnce(new Error("chunk download failed"))
|
|
.mockResolvedValue({ "test-feature": featureInput });
|
|
const application = createTestApplication({
|
|
featureLoaders: {
|
|
"test-feature": loader,
|
|
"foreign-feature": async () => ({ "test-feature": featureInput }),
|
|
},
|
|
});
|
|
|
|
expect(application.features.has("test-feature")).toBe(false);
|
|
expect(() => application.features.get("test-feature")).toThrow(
|
|
"Application feature is not loaded yet: test-feature",
|
|
);
|
|
await expect(application.features.load("test-feature")).rejects.toThrow(
|
|
"chunk download failed",
|
|
);
|
|
|
|
const first = application.features.load("test-feature");
|
|
expect(application.features.load("test-feature")).toBe(first);
|
|
await first;
|
|
expect(application.features.get("test-feature")).toBe(featureInput);
|
|
await application.features.load("test-feature");
|
|
await application.features.load("not-installed");
|
|
expect(loader).toHaveBeenCalledTimes(2);
|
|
|
|
await expect(application.features.load("foreign-feature")).rejects.toThrow(
|
|
"Feature foreign-feature installed an input for test-feature",
|
|
);
|
|
});
|
|
|
|
it("uses fake output ports for preference, session, and safe diagnostics flows", async () => {
|
|
const write = vi.fn(() => ({ ok: true as const }));
|
|
const emit = vi.fn();
|
|
const record = vi.fn();
|
|
const subscribe = vi.fn(() => () => {});
|
|
const beginSignIn = vi.fn(async () => {});
|
|
const signOut = vi.fn(async () => {});
|
|
const recover = vi.fn(async () => "restored" as const);
|
|
const ports = {
|
|
session: {
|
|
getState: () => "authenticated" as const,
|
|
subscribe,
|
|
beginSignIn,
|
|
signOut,
|
|
recover,
|
|
},
|
|
preferences: {
|
|
read: () => ({ ok: true as const, value: "dark" }),
|
|
write,
|
|
remove: () => ({ ok: true as const }),
|
|
},
|
|
diagnostics: { record },
|
|
telemetry: { emit },
|
|
releaseInfo: {
|
|
getCurrent: async () => ({
|
|
buildId: "build-a",
|
|
releaseId: "release-a",
|
|
configSchemaVersion: "1",
|
|
apiContractVersion: "1",
|
|
assetManifestHash: "hash-a",
|
|
routeChunks: { "route-home": "assets/home.js" },
|
|
}),
|
|
refresh: async () => ({
|
|
buildId: "build-a",
|
|
releaseId: "release-a",
|
|
configSchemaVersion: "1",
|
|
apiContractVersion: "1",
|
|
assetManifestHash: "hash-a",
|
|
routeChunks: { "route-home": "assets/home.js" },
|
|
}),
|
|
},
|
|
runtimeCapabilities: createRuntimeCapabilitiesStub(),
|
|
productFeatures: createProductFeaturesStub(),
|
|
navigation: { reload: () => {} },
|
|
} satisfies ApplicationOutputPorts;
|
|
const application = createApplication(ports);
|
|
|
|
expect(application.session.getSnapshot()).toBe("authenticated");
|
|
const listener = vi.fn();
|
|
expect(application.session.subscribe(listener)).toBeTypeOf("function");
|
|
expect(subscribe).toHaveBeenCalledWith(listener);
|
|
await application.session.beginSignIn("/return");
|
|
expect(beginSignIn).toHaveBeenCalledWith("/return");
|
|
await application.session.signOut();
|
|
expect(signOut).toHaveBeenCalledOnce();
|
|
await expect(application.session.recover()).resolves.toBe("restored");
|
|
expect(application.preferences.getColorScheme()).toBe("dark");
|
|
expect(application.preferences.setColorScheme("light")).toEqual({ ok: true });
|
|
expect(write).toHaveBeenCalledWith("COLOR_SCHEME", "light");
|
|
|
|
application.diagnostics.reportRenderFailure({
|
|
routeId: "APP_HOME",
|
|
buildId: "build-a",
|
|
boundaryName: "route",
|
|
});
|
|
expect(record).toHaveBeenCalledWith({
|
|
level: "error",
|
|
eventId: "ui.render.failed",
|
|
context: {
|
|
route_id: "APP_HOME",
|
|
build_id: "build-a",
|
|
component_boundary: "route",
|
|
},
|
|
});
|
|
expect(emit).toHaveBeenCalledWith("ui.render.failed", {
|
|
route_id: "APP_HOME",
|
|
build_id: "build-a",
|
|
component_boundary: "route",
|
|
});
|
|
application.diagnostics.reportRouteChanged({
|
|
routeId: "APP_HOME",
|
|
buildId: "build-a",
|
|
});
|
|
expect(record).toHaveBeenCalledWith({
|
|
level: "info",
|
|
eventId: "route.changed",
|
|
context: { route_id: "APP_HOME", build_id: "build-a" },
|
|
});
|
|
});
|
|
|
|
it("does not let a failing diagnostics output escape into presentation", () => {
|
|
const application = createTestApplication({
|
|
diagnostics: {
|
|
record() {
|
|
throw new Error("sink details");
|
|
},
|
|
},
|
|
telemetry: {
|
|
emit() {
|
|
throw new Error("telemetry details");
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(() =>
|
|
application.diagnostics.reportRenderFailure({
|
|
routeId: "APP_HOME",
|
|
buildId: "build-a",
|
|
boundaryName: "feature",
|
|
}),
|
|
).not.toThrow();
|
|
});
|
|
});
|