Files
clean-architecture-frontend…/tests/features/reference-feature/reference-http-gateway.test.ts
DongHyeonka fc303d89bc refactor(contracts): 폐기 별칭 import를 새 이름으로 옮기고 lint로 막는다 (07-01)
문제
MappingResult라는 이름이 두 모양을 가리킨다. external-contract-runtime.ts의
MappingResult({ ok:false, error:{ kind, code } })는 주석이 "정본"이라고
부르지만 테스트 말고 쓰는 곳이 없다. boundary-mapper.ts는
{ ok:false, code } 모양을 BoundaryMappingResult로 이름 붙이고 같은 이름
MappingResult를 @deprecated 별칭으로 남겼는데, 실행 경로가 그 별칭을
요구한다(feature-http-binding mapSuccess, client.ts, resource-mapper,
참조 mapper, boundary-mapper 자신의 helper 반환 타입). 그래서 별칭의 제거
조건("이 파일에서 MappingResult를 import하는 모듈이 없을 때")이 충족될 수
없다. ApiFailure 별칭도 포트 2개와 참조 기능을 포함해 7개 파일이 쓴다.
eslint 설정에 폐기 검사가 없다.

고른 방법 (리뷰 최소 개선 (1)·(4)와 lint, 공개 이름은 그대로)
- boundary-mapper의 BoundaryMapper.map, mapWithBoundaryRegistry,
  mappingSuccess, mappingFailure와 바인딩 mapSuccess가
  BoundaryMappingResult를 반환한다. 참조 mapper·client·resource-mapper도
  옮겼다. ApiFailure를 쓰던 파일은 AppFailure를 쓴다. 타입이 같아서
  런타임과 공개 시그니처는 바뀌지 않는다.
- D-15 주석을 실제와 맞췄다. 기능 mapper와 HTTP 바인딩은
  BoundaryMappingResult(닫힌 실패 코드)를 반환하고, 계약 패키지 쪽 결과가
  필요하면 toContractMappingResult로 바꾼다. 참조 기능 README의 "ApiFailure는
  같은 type의 alias" 문장도 고쳤다.
- 폐기 검사: 이 repo의 ESLint는 babel 파서라 타입 정보가 없어
  @typescript-eslint/no-deprecated를 쓸 수 없다. 대신 core
  no-restricted-imports의 patterns.importNames로 boundary-mapper의
  MappingResult와 errors의 ApiFailure import를 src·tests 전체에서 막는다.
  층별 no-restricted-imports 설정이 같은 규칙을 덮어쓰므로
  restrictedImports()가 별칭 패턴을 항상 덧붙이고, 층 규칙이 없는 파일은
  그 앞에 둔 공통 블록이 받는다.

버린 대안
- 별칭 export 삭제와 정본 이름을 ContractMappingResult로 바꾸기(리뷰 (2)
  후반·(3)): 다운스트림 import를 깨는 공개 이름 변경이다. 이번 묶음 규칙상
  공개 시그니처를 깨는 변경은 하지 않는다. 별칭 주석에 "repo 안 사용 0,
  lint로 강제, 제거는 minor 릴리스 + CHANGELOG [계약] 행"을 적었다.
- typescript-eslint 도입 후 no-deprecated: 새 의존성과 type-aware lint
  설정(속도·설정 범위)이 필요하다.
- 바인딩이 정본 모양을 받게 바꾸기(리뷰 C): 실패 코드가 닫힌 3종에서 자유
  문자열로 넓어져 계약이 약해진다.

위험·한계
- 이름 MappingResult는 여전히 두 파일에서 export된다(한쪽은 폐기 별칭).
  리뷰 완료 기준("MappingResult export 하나, grep 0건")은 별칭을 지워야
  충족된다. 제거 시점은 릴리스 결정으로 남긴다.
- 다운스트림이 eslint.config.ts를 동기화하면 그쪽의 별칭 import가 lint
  오류가 된다. 이름만 바꾸면 된다(tech-log는 mappingSuccess를 쓰는데,
  반환 타입은 같은 모양이라 영향 없음).
- adapters/http의 client.ts·feature-http-binding.ts는 타입 이름만 바꿨다.
  같은 파일을 고치는 다른 수정과 합칠 때 줄 단위 충돌이 날 수 있다.

검증
- RED: 규칙만 먼저 넣고 eslint src tests -> 9개 파일 11 errors
  ("'MappingResult' import from '../../contracts/boundary-mapper.ts' is
  restricted ... deprecated alias: import BoundaryMappingResult", ApiFailure
  같은 꼴).
- GREEN: lint 전체 범위(src scripts tests recipes .storybook 설정 파일)
  --max-warnings=0 rc=0. src에서 별칭을 쓰는 곳은 정의 줄뿐(git grep).
- 회귀: tsc app/test/node rc=0. run-vitest tests/architecture tests/unit
  tests/features tests/platform tests/component tests/contract
  tests/runtime-schema tests/integration(pnpm·corepack을 띄우는 4파일 제외)
  273 files / 3136 tests 중 3135 통과. 실패 1건은
  provider-guardian-transaction(guardian exit=126, 단독 실행도 같음, 이
  변경과 무관한 scripts/lib 프로세스 테스트).
  check-registries PASS, verify-documentation-readiness PASS_SCOPED,
  check-adapter-inventory PASS.
- 미실행: check:architecture(pnpm 필요). depcruise 직접 실행은 0 modules로
  사실상 미검증.

Refs: docs/reviews/2026-11-01-maturity-review/07-contracts.md
2026-11-01 22:35:54 +09:00

106 lines
3.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { Result } from "../../../src/contracts/result.ts";
import { createFailure, type AppFailure } from "../../../src/contracts/errors.ts";
import {
createReferenceHttpGateway,
type ReferenceHttpBinding,
} from "../../../src/features/reference-feature/adapters/reference-http-gateway.ts";
import type { ReferenceResource } from "../../../src/features/reference-feature/domain/reference-resource.ts";
const resources = Object.freeze({
first: Object.freeze({
id: "reference-1",
displayName: "First",
createdAt: null,
}),
created: Object.freeze({
id: "reference-2",
displayName: "Created",
createdAt: "2026-07-26T00:00:00.000Z",
}),
}) satisfies Readonly<Record<string, ReferenceResource>>;
type ScriptedResult = Result<
ReferenceResource | readonly ReferenceResource[],
AppFailure
>;
function scriptedBinding(results: ScriptedResult[]) {
const calls: Array<
readonly [operationId: string, input: unknown, context: unknown]
> = [];
let index = 0;
const execute = (async (
operationId: string,
input: unknown,
context?: unknown,
) => {
calls.push([operationId, input, context]);
const result = results[index];
index += 1;
if (!result) throw new Error("Missing scripted result");
return result;
}) as ReferenceHttpBinding["execute"];
return {
binding: Object.freeze({ execute }) satisfies ReferenceHttpBinding,
calls,
};
}
describe("reference HTTP operation gateway", () => {
it("delegates exact typed feature inputs to the capability binding", async () => {
const scripted = scriptedBinding([
{ ok: true, value: [resources.first] },
{ ok: true, value: resources.created },
{ ok: true, value: resources.first },
]);
const gateway = createReferenceHttpGateway(scripted.binding);
const signal = new AbortController().signal;
await expect(
gateway.list({ cursor: "next", limit: 20, tags: ["active"] }, { signal }),
).resolves.toEqual({ ok: true, value: [resources.first] });
await expect(
gateway.create({ name: "Created", note: "safe note" }),
).resolves.toEqual({ ok: true, value: resources.created });
await expect(
gateway.get("reference-1", { signal }),
).resolves.toEqual({ ok: true, value: resources.first });
expect(scripted.calls).toEqual([
[
"LIST_REFERENCE_RESOURCES",
{ cursor: "next", limit: 20, tags: ["active"] },
{ signal },
],
[
"CREATE_REFERENCE_RESOURCE",
{ name: "Created", note: "safe note" },
undefined,
],
[
"GET_REFERENCE_RESOURCE",
{ resourceId: "reference-1" },
{ signal },
],
]);
});
it("preserves a capability-normalized failure across the feature gateway", async () => {
const failure = createFailure(
"SCHEMA_MISMATCH",
"GET_REFERENCE_RESOURCE",
0,
);
const scripted = scriptedBinding([{ ok: false, error: failure }]);
const gateway = createReferenceHttpGateway(scripted.binding);
await expect(gateway.get("invalid")).resolves.toEqual({
ok: false,
error: failure,
});
});
});