/* * ★ **커넥터가 적은 선언이 게이트의 답으로 이어지는가** — 오늘 결함이 정확히 이 사이에서 났다. * * ── 무엇이 났나 (2026-09-02) ──────────────────────────────────────────────── * 시험은 두 쪽에 다 있었다. 등록 검사를 걷는 것(§`connector-capability-declaration.test.ts`)과 * 게이트 판정을 걷는 것(§`actuation-target.test.ts`). 그런데 **그 둘을 잇는 것이 없었다.** * * MES 커넥터가 actuate 를 다 만들었다 * 능력 축에 'actuate' 라는 이름이 없었다 ← 여기가 비어 있었다 * 커넥터는 ['live','control'] 만 적을 수 있었다 * 넘기는 자리는 「구현이 없습니다」로 답했다 * * 양쪽 시험은 각자 초록이었다. 이어 걷는 시험이 있었으면 그 자리에서 걸렸다. * * 그래서 이 파일은 **레지스트리에서 값을 꺼내** 게이트에 넣는다. 손으로 적은 값을 넣으면 오늘 났던 * 어긋남을 그대로 지나친다 — 그 어긋남이 레지스트리와 게이트 사이에 있었기 때문이다. */ import { test } from 'node:test' import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' /* 등록 검사가 경고로 말한다 — 그 말도 이 자리에서 함께 본다. */ const warnings: string[] = [] const originalWarn = console.warn console.warn = (...args: unknown[]) => { warnings.push(args.join(' ')) } process.on('exit', () => (console.warn = originalWarn)) const { registerAdapterType, getAdapter, capabilitiesOf } = await import( '../server/service/reference/reference-adapter.js' ) type ActuationReadiness = import('../server/service/reference/reference-adapter.js').ActuationReadiness const { actuationTarget, isActuationAllowed } = await import('../server/service/reference/actuation-target.js') let seq = 0 function register(over: Record) { const type = `seam-${++seq}` registerAdapterType({ type, async fetchMaster() { return {} as any }, ...over } as any) return type } /** * 등록된 커넥터의 **실제 값**으로 게이트에 묻는다 — 배선(§`actuation-routing.ts`)이 하는 것과 같다. * * 저장소만 여기서 대신한다. 트윈과 원본은 있는 것으로 두고, 갈리는 것은 커넥터가 무엇을 적었나다. */ function askGate(adapterType: string, siteId?: string) { /* * **기본값을 두지 않는다.** 처음에 `siteId = 'plant-a'` 로 두었더니 `askGate(type, undefined)` 가 * 기본값을 집어서 「사이트를 모르는 경우」를 시험할 수 없었다 — 시험이 초록인데 아무것도 확인하지 * 않는 상태였다. 부르는 쪽이 매번 적는다. */ const adapter = getAdapter(adapterType) return actuationTarget({ instanceId: 'twin-a', twinExists: true, siteId, ref: { source: 'twin-a', adapterType }, adapterRegistered: !!adapter, capabilities: capabilitiesOf(adapter), declaresActuate: !!adapter?.capabilities?.includes('actuate'), hasActuateImpl: typeof adapter?.actuate === 'function' }) } /* ── 선언과 구현이 다 있으면 게이트가 열린다 ────────────────────────────────── */ test('★ 커넥터가 조치를 적고 만들었으면 게이트가 열린다 — 이 한 줄이 없어서 하루가 갔다', () => { const before = warnings.length const type = register({ capabilities: ['live', 'actuate'], openLiveFeed: () => () => {}, actuate: async () => ({ ok: true }) }) assert.equal(warnings.length, before, '맞게 적었는데 등록이 무슨 말을 했다') const target = askGate(type, 'plant-a') assert.equal(isActuationAllowed(target), true, '커넥터는 조치를 낼 수 있는데 게이트가 막았다') assert.deepEqual(target, { ok: true, siteId: 'plant-a', adapterType: type, source: 'twin-a' }) }) /* ── 오늘 났던 상태를 그대로 세운다 ─────────────────────────────────────────── */ test('★ 구현만 있고 선언이 없으면 — 등록이 말하고, 게이트도 같은 것을 말한다', () => { /* * 이것이 오늘의 상태다. 두 자리가 **같은 원인을 같은 말로** 짚어야 한다. 등록 경고는 뜰 때 한 번 * 지나가고 아무도 안 볼 수 있다. 넘기려는 사람이 보는 것은 게이트의 답이다. */ const before = warnings.length const type = register({ capabilities: ['live'], openLiveFeed: () => () => {}, actuate: async () => ({ ok: true }) }) const said = warnings.slice(before).join('\n') assert.ok(said.includes('actuate'), '등록이 조치 선언이 빠진 것을 말하지 않았다') const target = askGate(type, 'plant-a') as any assert.equal(target.code, 'not-declared') assert.match(target.detail, /capabilities/, '게이트가 무엇을 넣어야 하는지 말하지 않았다') }) test('★ 선언만 있고 구현이 없으면 — 등록도 게이트도 말한다', () => { /* * 이 시험은 2026-09-16 까지 「등록은 조용하고, 게이트만 말한다」였다. 그때 주석이 그 침묵을 이렇게 * 적어 두었다 — 「등록 검사는 이 방향을 보지 않는다. 그래서 **게이트가 말하지 않으면 아무도 말하지 * 않는다**」. 그 문장이 곧 결함의 서술이었다: 조치를 넘기는 자리까지 가 본 사람만 그 사실을 듣고, * 커넥터를 만든 사람은 선언했으니 된 줄 안다. * * ADR-0036 ③ 개정으로 등록이 양방향을 본다. 게이트의 문장은 그대로다 — 그 사람은 조치를 하겠다고 * 적어 두었으니 「관측만 냅니다」는 여전히 사실이 아니다. */ const before = warnings.length const type = register({ capabilities: ['live', 'actuate'], openLiveFeed: () => () => {} }) const said = warnings.slice(before).join('\n') assert.ok(said.includes('actuate'), '등록이 증명 없는 선언을 말하지 않았다') assert.ok(said.includes('declares'), '등록이 어느 방향의 어긋남인지 말하지 않았다') assert.deepEqual(capabilitiesOf(getAdapter(type)), ['live'], '능력 판정이 구현 없는 선언을 걸러 내지 않았다') const target = askGate(type, 'plant-a') as any assert.equal(target.code, 'not-implemented') assert.doesNotMatch(target.detail, /관측만/) }) test('선언도 구현도 없으면 이 커넥터는 조치를 받지 않는다', () => { const type = register({ capabilities: ['live'], openLiveFeed: () => () => {} }) const target = askGate(type, 'plant-a') as any assert.equal(target.code, 'not-supported') assert.match(target.detail, /관측만/) }) /* ── 게이트가 여는 것은 능력 판정을 지난 것뿐이다 ──────────────────────────── */ test('★ 등록된 커넥터마다 게이트의 답이 능력 판정과 어긋나지 않는다', () => { /* * 이것이 이 파일의 요점이다. 「능력에 actuate 가 있다」와 「게이트가 열린다」가 **항상 같이** 가야 * 한다. 오늘은 둘이 갈렸다 — 능력 축에 그 이름이 없어서 앞엣것이 영원히 거짓이었고, 게이트는 * 그것과 무관하게 무조건 닫혀 있었다. */ const cases = [ { capabilities: ['live', 'actuate'], openLiveFeed: () => () => {}, actuate: async () => ({ ok: true }) }, { capabilities: ['live'], openLiveFeed: () => () => {}, actuate: async () => ({ ok: true }) }, { capabilities: ['live', 'actuate'], openLiveFeed: () => () => {} }, { capabilities: ['actuate'], actuate: async () => ({ ok: true }) }, { capabilities: ['live'], openLiveFeed: () => () => {} }, {} ] for (const spec of cases) { const type = register(spec) const canActuate = capabilitiesOf(getAdapter(type)).includes('actuate') const opened = isActuationAllowed(askGate(type, 'plant-a')) assert.equal( opened, canActuate, `능력 판정은 ${canActuate} 인데 게이트는 ${opened} 로 답했다 (${JSON.stringify(Object.keys(spec))})` ) } }) /* ── 사이트를 모르면 능력과 무관하게 닫힌다 ────────────────────────────────── */ test('★ 조치를 낼 수 있는 커넥터라도 사이트를 모르면 닫힌다 — 잘못된 공장이 만든다', () => { const type = register({ capabilities: ['actuate'], actuate: async () => ({ ok: true }) }) assert.equal(isActuationAllowed(askGate(type, 'plant-a')), true) assert.equal((askGate(type, undefined) as any).code, 'no-site') assert.equal((askGate(type, ' ') as any).code, 'no-site') }) test('등록되지 않은 커넥터를 가리키면 능력을 묻기 전에 닫힌다', () => { const target = askGate('seam-없는-커넥터', 'plant-a') as any assert.equal(target.code, 'no-adapter') assert.match(target.detail, /seam-없는-커넥터/, '어느 커넥터인지 말하지 않으면 찾을 수 없다') }) /* ── 저쪽이 받을 준비가 됐나 ────────────────────────────────────────────────── */ test('★ 확인할 길이 없으면 「준비됐다」로 답하지 않는다 — 없는 확인을 통과로 읽지 않게', async () => { /* * 실측(2026-09-03): 승인된 조치를 넘겼더니 저쪽이 503 을 답했다 — 저쪽 프로세스에 비밀값이 실려 * 있지 않았다. 우리 쪽 설정·주소·서명은 다 맞았다. 보내 보기 전에는 알 수 없어서 사람이 승인 * 화면까지 가서 누르고, 실패를 보고, 다시 로그인했다. * * 그래서 커넥터에 「받을 준비가 됐나」를 묻는 얼굴을 뒀다. 안 만든 커넥터에 대해 이 자리가 * 「준비됐다」로 답하면, 얼굴이 있으나 없으나 같아진다. */ const type = register({ capabilities: ['actuate'], actuate: async () => ({ ok: true }) }) const adapter = getAdapter(type) assert.equal(typeof adapter?.actuationReadiness, 'undefined', '이 커넥터는 그 얼굴을 만들지 않았다') /* 판정만 걷는다 — 배선은 저장소를 지나므로 여기서 세우지 않는다(§ 이 파일의 머리말). */ const answer = notCheckable(type) assert.equal(answer.ready, undefined, '모름을 참·거짓으로 답했다') assert.equal(answer.code, 'not-checkable') }) test('★ 「모른다」와 「안 된다」가 다른 값이다', () => { const unknown = notCheckable('some-connector') const refused: ActuationReadiness = { checked: 'local', ready: false, reason: '주소가 없습니다', code: 'no-endpoint' } assert.equal(unknown.ready, undefined) assert.equal(refused.ready, false) assert.notEqual(unknown.code, refused.code) }) test('어디까지 봤는지 함께 답한다 — 「살아 있다고 말한 적 없다」와 「죽었다」는 다르다', () => { assert.equal(notCheckable('x').checked, 'local') }) /** * 배선이 커넥터에 얼굴이 없을 때 만드는 답 — 그 모양을 여기서 못 박는다. * * 저장소를 지나는 함수(§`actuationReadinessOf`)를 부르면 시험이 TypeORM 을 세워야 한다. 그 답의 * **모양**이 계약이고, 모양이 바뀌면 화면이 조용히 다르게 읽는다. */ function notCheckable(adapterType: string): ActuationReadiness { return { checked: 'local', reason: `커넥터 "${adapterType}" 는 저쪽이 받을 준비가 됐는지 알려 주지 않습니다 — 넘겨 보고 알게 됩니다`, code: 'not-checkable' } } /* ── 화면이 부를 자리가 있는가 ─────────────────────────────────────────────── */ test('★ 판정 함수를 부르는 자리가 있다 — 없으면 화면이 물을 방법이 없다', () => { /* * 판정을 만들어 두고 **부르는 자리를 안 만들었다.** 인티그레이션 레인이 두 번 짚어 줬다 — * `actuationTargetOf` 도, 오늘 만든 `actuationReadinessOf` 도 부르는 곳이 없었다. * * 그래서 못 넘기는 조치도 눌러 보고 알게 됐고, 저쪽에 비밀값이 없던 날 승인 하나가 헛돌았다. * 이 시험은 그 자리가 스키마에 서 있는지 본다 — 문자열로 세는 것이 약하지만, 없어지는 것을 * 잡는 데는 충분하다(리졸버를 세우려면 type-graphql 스키마를 지어야 한다). */ const source = readFileSync( new URL('../server/service/actuation/twin-command-resolver.ts', import.meta.url).pathname, 'utf-8' ) assert.match(source, /twinActuationReadiness/, '화면이 부를 조회가 없다') assert.match(source, /actuationTargetOf/, '대상 판정을 부르지 않는다') assert.match(source, /actuationReadinessOf/, '준비 판정을 부르지 않는다') /* 조회여야 한다 — 이 답으로 넘김을 막지 않으므로 뮤테이션이 아니다. */ const at = source.indexOf('twinActuationReadiness') const before = source.slice(Math.max(0, at - 400), at) assert.match(before, /@Query/, '알림인데 뮤테이션으로 두었다') })