Files
2nd/10_Wiki/Topics/Architecture/Preprocessing Seam (전처리 접점).md
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

4.1 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-preprocessing-seam-전처리-접점 Preprocessing Seam (전처리 접점) 10_Wiki/Topics verified self
Preprocessing Seam
전처리 접점
Feathers Seam
link seam
none A 0.9 applied
legacy-code
testing
refactoring
seam
2026-05-10 pending
language framework
c-cpp-python legacy-refactoring

Preprocessing Seam (전처리 접점)

매 한 줄

"매 컴파일 전에 매 동작을 바꾸는 매 접점". Preprocessing seam은 Michael Feathers "Working Effectively with Legacy Code" (2004) 의 매 3대 seam (preprocessing / link / object) 중 매 첫 번째 — 매 source 수정 없이 매 매크로/include 치환으로 매 test isolation 가능 지점. C/C++ 같은 매 preprocessor-heavy language의 매 testability 회복 도구.

매 핵심

매 Seam 정의

  • 매 Seam: 매 source 수정 없이 매 동작 변경 가능한 매 지점.
  • 매 Enabling point: 매 seam을 매 활용하는 매 mechanism (here: preprocessor).
  • 매 3종류: preprocessing / link / object.

매 Preprocessing seam 작동

  • #include "db.h" → 매 test 시 매 fake db.h include path 우선.
  • #define malloc test_malloc → 매 allocator hook.
  • #ifdef TESTING 매 conditional compile.

매 응용

  1. Legacy C codebase 매 unit test 추가.
  2. Embedded firmware의 매 hardware register hook.
  3. Time/random 매 deterministic replacement.

💻 패턴

Header substitution seam

// production: src/db.h
int db_query(const char* sql);

// test/fakes/db.h — 매 same signature, 매 fake impl
int db_query(const char* sql) { return 42; }

// CMake test target
target_include_directories(my_test PRIVATE test/fakes src)  // 매 fakes 우선

Macro override

// production: alloc.h
#ifndef TESTING
#  define MY_MALLOC malloc
#  define MY_FREE   free
#else
#  define MY_MALLOC test_malloc
#  define MY_FREE   test_free
#endif

void* p = MY_MALLOC(64);

Time seam (deterministic test)

// time_seam.h
#ifdef TESTING
extern uint64_t mock_now;
#  define NOW_MS() (mock_now)
#else
#  define NOW_MS() ((uint64_t)(clock_gettime_ms()))
#endif

// test
uint64_t mock_now = 1000;
mock_now += 500;
ASSERT(elapsed() == 500);

Linker seam (sibling)

// production link: real_sensor.o
int read_sensor(void);

// test link: fake_sensor.o  매 same symbol, 매 different impl
int read_sensor(void) { return injected_value; }

// gcc test.c fake_sensor.o -o test  // 매 real_sensor.o 미포함

Python equivalent — sys.modules patch

# 매 import-time seam
import sys, types
fake = types.ModuleType("db")
fake.query = lambda sql: 42
sys.modules["db"] = fake

import service  # 매 service.py 의 `import db` → fake

매 결정 기준

상황 Approach
C/C++ legacy, 매 source 매 못 건드림 Preprocessing seam
Static lib, 매 link-time control Link seam
Java/.NET runtime Object seam (subclass / DI)
Python sys.modules / monkeypatch

기본값: Object seam 우선, 매 안 되면 link → preprocessing 순.

🔗 Graph

🤖 LLM 활용

언제: legacy C/C++ 매 testability 회복, 매 hardware seam 설계. 언제 X: 매 greenfield project (DI 우선).

안티패턴

  • 매 #ifdef TESTING 폭주: 매 production code 매 #ifdef 매 가독성 파괴.
  • 매 Header path race: 매 fake include order 매 fragile.
  • 매 Macro hell: 매 함수 매크로 매 debug 불가.
  • 매 매 seam 영구화: 매 test seam 을 매 production refactor 후에도 매 유지.

🧪 검증 / 중복

  • Verified (Feathers "Working Effectively with Legacy Code" 2004 Ch.4).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — Feathers 3-seam taxonomy + working C/Python examples