Files
2nd/10_Wiki/Topics/Domain_Programming/Architecture/Preprocessing Seam (전처리 접점).md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

144 lines
4.1 KiB
Markdown

---
id: wiki-2026-0508-preprocessing-seam-전처리-접점
title: Preprocessing Seam (전처리 접점)
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Preprocessing Seam, 전처리 접점, Feathers Seam, link seam]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [legacy-code, testing, refactoring, seam]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: c-cpp-python
framework: 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
```c
// 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
```c
// 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)
```c
// 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)
```c
// 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
```python
# 매 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
- 부모: [[Seam]]
- 변형: [[Link-Seam]] · [[Object-Seam]]
- 응용: [[Unit-Testing]]
- Adjacent: [[Dependency_Injection_(DI)|Dependency-Injection]] · [[Test-Double]]
## 🤖 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 |