onto-mcp 0.3.2 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.onto/processes/reconstruct/actionable-ontology-seed-recomposition-design.md +447 -0
- package/.onto/processes/reconstruct/foundry-style-ontology-seed-contract.md +934 -0
- package/.onto/processes/reconstruct/reconstruct-boundary-contract.md +303 -725
- package/.onto/processes/reconstruct/reconstruct-contract-registry.yaml +1645 -0
- package/.onto/processes/reconstruct/reconstruct-execution-ux-contract.md +26 -22
- package/.onto/processes/reconstruct/source-profile-contract.md +49 -23
- package/.onto/processes/reconstruct/source-profiles/code.md +6 -3
- package/.onto/processes/reconstruct/source-profiles/database.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/document.md +5 -2
- package/.onto/processes/reconstruct/source-profiles/spreadsheet.md +5 -4
- package/.onto/processes/review/review-execution-ux-contract.md +40 -0
- package/.onto/processes/shared/pipeline-execution-ledger-contract.md +26 -10
- package/.onto/processes/shared/target-material-kind-contract.md +29 -16
- package/AGENTS.md +6 -4
- package/README.md +149 -76
- package/dist/cli.js +8 -8
- package/dist/core-api/reconstruct-api.js +117 -31
- package/dist/core-api/review-api.js +47 -0
- package/dist/core-runtime/cli/codex-review-unit-executor.js +39 -2
- package/dist/core-runtime/cli/complete-review-session.js +2 -2
- package/dist/core-runtime/cli/mock-review-unit-executor.js +1 -1
- package/dist/core-runtime/cli/review-invoke.js +9 -9
- package/dist/core-runtime/cli/run-review-prompt-execution.js +39 -5
- package/dist/core-runtime/cli/spawn-watcher.js +266 -47
- package/dist/core-runtime/cli/start-review-session.js +3 -3
- package/dist/core-runtime/llm/llm-caller.js +11 -0
- package/dist/core-runtime/llm/llm-tool-loop.js +2 -0
- package/dist/core-runtime/observability/runtime-stream-observation.js +118 -0
- package/dist/core-runtime/onboard/cli-host.js +174 -0
- package/dist/core-runtime/onboard/host-target.js +22 -0
- package/dist/core-runtime/onboard/json-config-host.js +122 -0
- package/dist/core-runtime/onboard/path-scan.js +26 -0
- package/dist/core-runtime/onboard/prompt.js +51 -0
- package/dist/core-runtime/onboard/register.js +214 -0
- package/dist/core-runtime/onboard/types.js +27 -0
- package/dist/core-runtime/reconstruct/actionable-seed-validation.js +1777 -0
- package/dist/core-runtime/reconstruct/artifact-types.js +10 -4
- package/dist/core-runtime/reconstruct/contract-registry.js +623 -0
- package/dist/core-runtime/reconstruct/domain-id.js +10 -0
- package/dist/core-runtime/reconstruct/governing-snapshot.js +716 -0
- package/dist/core-runtime/reconstruct/material-profile-validation.js +191 -0
- package/dist/core-runtime/reconstruct/materialize-preparation.js +49 -11
- package/dist/core-runtime/reconstruct/pipeline-execution-ledger.js +269 -79
- package/dist/core-runtime/reconstruct/post-seed-validation.js +1194 -51
- package/dist/core-runtime/reconstruct/record.js +104 -20
- package/dist/core-runtime/reconstruct/run.js +2107 -413
- package/dist/core-runtime/reconstruct/seed-claim-projections.js +268 -0
- package/dist/core-runtime/reconstruct/source-profiles.js +93 -4
- package/dist/core-runtime/reconstruct/terminal-validation.js +807 -0
- package/dist/core-runtime/review/review-invocation-runner.js +4 -4
- package/dist/mcp/server.js +110 -38
- package/dist/mcp/tool-schemas.js +20 -6
- package/package.json +8 -17
- package/scripts/onto-review-watch.sh +486 -0
- package/scripts/onto-runtime-watch.sh +122 -0
- package/scripts/postinstall-hint.js +22 -0
- package/.onto/processes/reconstruct/top-level-concept-discovery-contract.md +0 -387
- package/dist/core-runtime/cli/bootstrap-review-binding.js +0 -186
- package/dist/core-runtime/cli/codex-nested-dispatch.test.js +0 -390
- package/dist/core-runtime/cli/codex-nested-teamlead-executor.test.js +0 -335
- package/dist/core-runtime/cli/coordinator-helpers.js +0 -583
- package/dist/core-runtime/cli/coordinator-state-machine-deliberation.test.js +0 -167
- package/dist/core-runtime/cli/coordinator-state-machine.js +0 -794
- package/dist/core-runtime/cli/e2e-codex-multi-agent-fixes.test.js +0 -615
- package/dist/core-runtime/cli/e2e-start-review-session.test.js +0 -312
- package/dist/core-runtime/cli/health.js +0 -44
- package/dist/core-runtime/cli/inline-http-review-unit-executor.test.js +0 -567
- package/dist/core-runtime/cli/materialize-review-execution-preparation.js +0 -104
- package/dist/core-runtime/cli/migrate-session-roots.js +0 -118
- package/dist/core-runtime/cli/repo-layout-migration-replace.smoke.test.js +0 -106
- package/dist/core-runtime/cli/review-invoke-auto-resolution.test.js +0 -268
- package/dist/core-runtime/cli/review-invoke-coordinator-topology.test.js +0 -136
- package/dist/core-runtime/cli/review-invoke-resolver-caching.test.js +0 -201
- package/dist/core-runtime/cli/review-invoke-topology-dispatch.test.js +0 -192
- package/dist/core-runtime/cli/session-root-guard.js +0 -168
- package/dist/core-runtime/cli/spawn-watcher.test.js +0 -457
- package/dist/core-runtime/cli/strip-wrapping-code-fence.test.js +0 -79
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.js +0 -412
- package/dist/core-runtime/cli/teamcreate-lens-deliberation-executor.test.js +0 -351
- package/dist/core-runtime/cli/topology-executor-mapping.js +0 -139
- package/dist/core-runtime/cli/topology-executor-mapping.test.js +0 -173
- package/dist/core-runtime/cli/write-review-interpretation.js +0 -81
- package/dist/core-runtime/config/onto-config-cli.js +0 -278
- package/dist/core-runtime/config/onto-config-key-path.js +0 -288
- package/dist/core-runtime/config/onto-config-key-path.test.js +0 -195
- package/dist/core-runtime/config/onto-config-preview.js +0 -108
- package/dist/core-runtime/config/onto-config-preview.test.js +0 -132
- package/dist/core-runtime/discovery/config-chain.js +0 -118
- package/dist/core-runtime/discovery/config-chain.test.js +0 -103
- package/dist/core-runtime/discovery/config-profile.js +0 -199
- package/dist/core-runtime/discovery/config-profile.test.js +0 -233
- package/dist/core-runtime/discovery/host-detection.test.js +0 -186
- package/dist/core-runtime/discovery/installation-paths.test.js +0 -65
- package/dist/core-runtime/discovery/lens-registry.test.js +0 -81
- package/dist/core-runtime/discovery/path-normalization.test.js +0 -22
- package/dist/core-runtime/discovery/plugin-path.js +0 -72
- package/dist/core-runtime/discovery/plugin-path.test.js +0 -95
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.js +0 -344
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile-defense.test.js +0 -915
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.js +0 -564
- package/dist/core-runtime/evolve/adapters/code-product/compile/compile.test.js +0 -708
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.js +0 -165
- package/dist/core-runtime/evolve/adapters/code-product/parsers/brief-parser.test.js +0 -227
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.js +0 -59
- package/dist/core-runtime/evolve/adapters/code-product/validators/validate.test.js +0 -205
- package/dist/core-runtime/evolve/adapters/methodology/adapter.js +0 -16
- package/dist/core-runtime/evolve/adapters/methodology/adapter.test.js +0 -9
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.js +0 -298
- package/dist/core-runtime/evolve/adapters/methodology/perspectives/authority-consistency.test.js +0 -70
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.js +0 -46
- package/dist/core-runtime/evolve/adapters/methodology/scope-types/process.test.js +0 -73
- package/dist/core-runtime/evolve/adapters/registry.js +0 -47
- package/dist/core-runtime/evolve/adapters/registry.test.js +0 -67
- package/dist/core-runtime/evolve/cli.js +0 -256
- package/dist/core-runtime/evolve/commands/align.js +0 -194
- package/dist/core-runtime/evolve/commands/align.test.js +0 -82
- package/dist/core-runtime/evolve/commands/apply.js +0 -161
- package/dist/core-runtime/evolve/commands/apply.test.js +0 -138
- package/dist/core-runtime/evolve/commands/close.js +0 -39
- package/dist/core-runtime/evolve/commands/close.test.js +0 -99
- package/dist/core-runtime/evolve/commands/defer.js +0 -40
- package/dist/core-runtime/evolve/commands/defer.test.js +0 -134
- package/dist/core-runtime/evolve/commands/draft.js +0 -323
- package/dist/core-runtime/evolve/commands/draft.test.js +0 -178
- package/dist/core-runtime/evolve/commands/e2e-evolve-full-cycle.test.js +0 -208
- package/dist/core-runtime/evolve/commands/error-messages.js +0 -125
- package/dist/core-runtime/evolve/commands/error-messages.test.js +0 -167
- package/dist/core-runtime/evolve/commands/propose-align.js +0 -222
- package/dist/core-runtime/evolve/commands/propose-align.test.js +0 -136
- package/dist/core-runtime/evolve/commands/reconstruct.js +0 -330
- package/dist/core-runtime/evolve/commands/reconstruct.test.js +0 -278
- package/dist/core-runtime/evolve/commands/shared.js +0 -22
- package/dist/core-runtime/evolve/commands/stale-check.js +0 -103
- package/dist/core-runtime/evolve/commands/stale-check.test.js +0 -84
- package/dist/core-runtime/evolve/commands/start.js +0 -887
- package/dist/core-runtime/evolve/commands/start.test.js +0 -396
- package/dist/core-runtime/evolve/config/project-config.js +0 -99
- package/dist/core-runtime/evolve/config/project-config.test.js +0 -170
- package/dist/core-runtime/evolve/renderers/align-packet.js +0 -280
- package/dist/core-runtime/evolve/renderers/align-packet.test.js +0 -332
- package/dist/core-runtime/evolve/renderers/draft-packet.js +0 -303
- package/dist/core-runtime/evolve/renderers/draft-packet.test.js +0 -377
- package/dist/core-runtime/evolve/renderers/format.js +0 -5
- package/dist/core-runtime/evolve/renderers/scope-md.js +0 -237
- package/dist/core-runtime/evolve/renderers/scope-md.test.js +0 -306
- package/dist/core-runtime/govern/cli.js +0 -369
- package/dist/core-runtime/govern/cli.test.js +0 -314
- package/dist/core-runtime/govern/drift-engine.js +0 -103
- package/dist/core-runtime/govern/drift-engine.test.js +0 -319
- package/dist/core-runtime/govern/promote-principle.js +0 -206
- package/dist/core-runtime/govern/promote-principle.test.js +0 -368
- package/dist/core-runtime/govern/queue.js +0 -81
- package/dist/core-runtime/govern/types.js +0 -16
- package/dist/core-runtime/install/cli.js +0 -530
- package/dist/core-runtime/install/detect.js +0 -128
- package/dist/core-runtime/install/detect.test.js +0 -155
- package/dist/core-runtime/install/gitignore-update.js +0 -74
- package/dist/core-runtime/install/gitignore-update.test.js +0 -64
- package/dist/core-runtime/install/install-integration.test.js +0 -373
- package/dist/core-runtime/install/prompts.js +0 -389
- package/dist/core-runtime/install/prompts.test.js +0 -293
- package/dist/core-runtime/install/types.js +0 -26
- package/dist/core-runtime/install/validation.js +0 -295
- package/dist/core-runtime/install/validation.test.js +0 -313
- package/dist/core-runtime/install/writer.js +0 -254
- package/dist/core-runtime/install/writer.test.js +0 -218
- package/dist/core-runtime/learning/extractor.js +0 -461
- package/dist/core-runtime/learning/feedback.js +0 -179
- package/dist/core-runtime/learning/health-report.js +0 -165
- package/dist/core-runtime/learning/health-report.test.js +0 -169
- package/dist/core-runtime/learning/loader.js +0 -388
- package/dist/core-runtime/learning/loader.test.js +0 -102
- package/dist/core-runtime/learning/promote/apply-state.js +0 -240
- package/dist/core-runtime/learning/promote/audit-obligation.js +0 -195
- package/dist/core-runtime/learning/promote/collector.js +0 -432
- package/dist/core-runtime/learning/promote/degraded-state.js +0 -125
- package/dist/core-runtime/learning/promote/domain-doc-proposer.js +0 -166
- package/dist/core-runtime/learning/promote/e2e-promote.test.js +0 -6385
- package/dist/core-runtime/learning/promote/health-snapshot.js +0 -150
- package/dist/core-runtime/learning/promote/insight-reclassifier.js +0 -544
- package/dist/core-runtime/learning/promote/judgment-auditor.js +0 -517
- package/dist/core-runtime/learning/promote/panel-reviewer.js +0 -1158
- package/dist/core-runtime/learning/promote/promote-executor.js +0 -1675
- package/dist/core-runtime/learning/promote/promoter.js +0 -307
- package/dist/core-runtime/learning/promote/retirement.js +0 -122
- package/dist/core-runtime/learning/promote/types.js +0 -23
- package/dist/core-runtime/learning/prompt-sections.js +0 -51
- package/dist/core-runtime/learning/shared/artifact-registry-init.js +0 -45
- package/dist/core-runtime/learning/shared/artifact-registry.js +0 -254
- package/dist/core-runtime/learning/shared/audit-obligation-kernel.js +0 -73
- package/dist/core-runtime/learning/shared/audit-state.js +0 -99
- package/dist/core-runtime/learning/shared/duplicate-check.js +0 -28
- package/dist/core-runtime/learning/shared/llm-caller.js +0 -831
- package/dist/core-runtime/learning/shared/llm-caller.test.js +0 -601
- package/dist/core-runtime/learning/shared/llm-tool-loop.js +0 -393
- package/dist/core-runtime/learning/shared/mode.js +0 -25
- package/dist/core-runtime/learning/shared/paths.js +0 -84
- package/dist/core-runtime/learning/shared/paths.test.js +0 -79
- package/dist/core-runtime/learning/shared/patterns.js +0 -37
- package/dist/core-runtime/learning/shared/recoverability.js +0 -355
- package/dist/core-runtime/learning/shared/recovery-context.js +0 -374
- package/dist/core-runtime/learning/shared/scope.js +0 -1
- package/dist/core-runtime/learning/shared/semantic-classifier.js +0 -94
- package/dist/core-runtime/learning/shared/specs/apply-execution-state-spec.js +0 -42
- package/dist/core-runtime/learning/shared/specs/audit-state-spec.js +0 -37
- package/dist/core-runtime/learning/shared/specs/backup-metadata-spec.js +0 -39
- package/dist/core-runtime/learning/shared/specs/emergency-log-spec.js +0 -41
- package/dist/core-runtime/learning/shared/specs/layout-version-spec.js +0 -38
- package/dist/core-runtime/learning/shared/specs/promote-decisions-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/promote-report-spec.js +0 -113
- package/dist/core-runtime/learning/shared/specs/prune-log-spec.js +0 -36
- package/dist/core-runtime/learning/shared/specs/recovery-resolution-spec.js +0 -48
- package/dist/core-runtime/learning/shared/specs/restore-manifest-spec.js +0 -43
- package/dist/core-runtime/learning/shared/specs/spec-helpers.js +0 -64
- package/dist/core-runtime/learning/usage-tracker.js +0 -190
- package/dist/core-runtime/learning/usage-tracker.test.js +0 -176
- package/dist/core-runtime/onboard/detect-review-axes.js +0 -122
- package/dist/core-runtime/onboard/detect-review-axes.test.js +0 -127
- package/dist/core-runtime/onboard/write-review-block.js +0 -188
- package/dist/core-runtime/onboard/write-review-block.test.js +0 -240
- package/dist/core-runtime/readers/brownfield-builder.js +0 -150
- package/dist/core-runtime/readers/brownfield-builder.test.js +0 -136
- package/dist/core-runtime/readers/code-chunk-collector.js +0 -53
- package/dist/core-runtime/readers/code-chunk-collector.test.js +0 -136
- package/dist/core-runtime/readers/file-utils.js +0 -240
- package/dist/core-runtime/readers/file-utils.test.js +0 -146
- package/dist/core-runtime/readers/lexicon-citation-check.js +0 -93
- package/dist/core-runtime/readers/lexicon-citation-check.test.js +0 -77
- package/dist/core-runtime/readers/mcp-figma.js +0 -30
- package/dist/core-runtime/readers/mcp-figma.test.js +0 -82
- package/dist/core-runtime/readers/mcp-generic.js +0 -31
- package/dist/core-runtime/readers/mcp-generic.test.js +0 -76
- package/dist/core-runtime/readers/ontology-index.js +0 -148
- package/dist/core-runtime/readers/ontology-index.test.js +0 -245
- package/dist/core-runtime/readers/ontology-query.js +0 -168
- package/dist/core-runtime/readers/ontology-query.test.js +0 -311
- package/dist/core-runtime/readers/ontology-resolve.js +0 -48
- package/dist/core-runtime/readers/ontology-resolve.test.js +0 -48
- package/dist/core-runtime/readers/patterns/index.js +0 -7
- package/dist/core-runtime/readers/review-log.js +0 -213
- package/dist/core-runtime/readers/review-log.test.js +0 -313
- package/dist/core-runtime/readers/scan-local.js +0 -102
- package/dist/core-runtime/readers/scan-local.test.js +0 -102
- package/dist/core-runtime/readers/scan-tarball.js +0 -121
- package/dist/core-runtime/readers/scan-tarball.test.js +0 -283
- package/dist/core-runtime/readers/scan-vault.js +0 -34
- package/dist/core-runtime/readers/scan-vault.test.js +0 -81
- package/dist/core-runtime/readers/types.js +0 -42
- package/dist/core-runtime/readers/types.test.js +0 -94
- package/dist/core-runtime/readers/viewpoint-collectors.js +0 -229
- package/dist/core-runtime/reconstruct/seed-candidate-validation.js +0 -385
- package/dist/core-runtime/review/citation-audit.test.js +0 -165
- package/dist/core-runtime/review/execution-plan-resolver.js +0 -247
- package/dist/core-runtime/review/execution-plan-resolver.test.js +0 -243
- package/dist/core-runtime/review/execution-topology-resolver-axis-first.test.js +0 -246
- package/dist/core-runtime/review/execution-topology-resolver.js +0 -401
- package/dist/core-runtime/review/execution-topology-resolver.test.js +0 -315
- package/dist/core-runtime/review/inline-context-embedder.test.js +0 -154
- package/dist/core-runtime/review/legacy-mode-policy.js +0 -88
- package/dist/core-runtime/review/materializers-effort-persist.test.js +0 -79
- package/dist/core-runtime/review/ontology-path-classifier.js +0 -179
- package/dist/core-runtime/review/ontology-path-classifier.test.js +0 -216
- package/dist/core-runtime/review/packet-boundary-policy.test.js +0 -107
- package/dist/core-runtime/review/participating-lens-paths.test.js +0 -73
- package/dist/core-runtime/review/review-config-legacy-translate.js +0 -244
- package/dist/core-runtime/review/review-config-legacy-translate.test.js +0 -161
- package/dist/core-runtime/review/review-config-validator.js +0 -289
- package/dist/core-runtime/review/review-config-validator.test.js +0 -236
- package/dist/core-runtime/review/shape-pipeline-audit.test.js +0 -311
- package/dist/core-runtime/review/shape-to-topology-id.js +0 -117
- package/dist/core-runtime/review/shape-to-topology-id.test.js +0 -132
- package/dist/core-runtime/review/topology-shape-derivation.js +0 -155
- package/dist/core-runtime/review/topology-shape-derivation.test.js +0 -195
- package/dist/core-runtime/scope-runtime/constants.js +0 -12
- package/dist/core-runtime/scope-runtime/constraint-pool.js +0 -166
- package/dist/core-runtime/scope-runtime/constraint-pool.test.js +0 -674
- package/dist/core-runtime/scope-runtime/domain-validation-log.js +0 -135
- package/dist/core-runtime/scope-runtime/domain-validation-log.test.js +0 -156
- package/dist/core-runtime/scope-runtime/eval-persistence.js +0 -65
- package/dist/core-runtime/scope-runtime/eval-persistence.test.js +0 -84
- package/dist/core-runtime/scope-runtime/event-pipeline.js +0 -64
- package/dist/core-runtime/scope-runtime/event-pipeline.test.js +0 -450
- package/dist/core-runtime/scope-runtime/event-store.js +0 -39
- package/dist/core-runtime/scope-runtime/event-store.test.js +0 -95
- package/dist/core-runtime/scope-runtime/gate-guard.js +0 -348
- package/dist/core-runtime/scope-runtime/gate-guard.test.js +0 -1047
- package/dist/core-runtime/scope-runtime/hash.js +0 -4
- package/dist/core-runtime/scope-runtime/hash.test.js +0 -33
- package/dist/core-runtime/scope-runtime/id.js +0 -4
- package/dist/core-runtime/scope-runtime/id.test.js +0 -17
- package/dist/core-runtime/scope-runtime/reducer.js +0 -297
- package/dist/core-runtime/scope-runtime/reducer.test.js +0 -759
- package/dist/core-runtime/scope-runtime/scope-manager.js +0 -161
- package/dist/core-runtime/scope-runtime/state-machine.js +0 -309
- package/dist/core-runtime/scope-runtime/state-machine.test.js +0 -704
- package/dist/core-runtime/scope-runtime/types.js +0 -116
- package/dist/core-runtime/scope-runtime/types.test.js +0 -69
- package/dist/core-runtime/translate/render-for-user.js +0 -169
- package/dist/core-runtime/translate/render-for-user.test.js +0 -122
- package/dist/providers/capability-contract.js +0 -1
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { collectRelevantChunks } from "./code-chunk-collector.js";
|
|
3
|
-
// ─── Fixtures ───
|
|
4
|
-
const RESOLVED = [
|
|
5
|
-
{ reference: "TrialLectureCommandServiceImpl.create()", resolved_files: ["src/TrialLectureCommandServiceImpl.java"], resolution_method: "filename" },
|
|
6
|
-
{ reference: "UnknownService.call()", resolved_files: [], resolution_method: "unresolved" },
|
|
7
|
-
];
|
|
8
|
-
const ONTOLOGY_RESULT = {
|
|
9
|
-
matched_entities: ["TrialLesson", "Ticket"],
|
|
10
|
-
code_locations: [{ reference: "TrialLectureCommandServiceImpl.create()", context: "Action TRIAL-1", entity: "TrialLesson" }],
|
|
11
|
-
db_tables: ["GT_CLASS"],
|
|
12
|
-
related_actions: [{ id: "TRIAL-1", display_name: "체험 수업 생성", source_code: "TrialLectureCommandServiceImpl.create()" }],
|
|
13
|
-
related_transitions: [],
|
|
14
|
-
value_filters: [{ entity: "TrialLesson", column: "CITY", value: "PODO_TRIAL", description: "체험 수업" }],
|
|
15
|
-
total_glossary_count: 2,
|
|
16
|
-
};
|
|
17
|
-
const SCAN_RESULT = {
|
|
18
|
-
source: { type: "add-dir", path: "./src" },
|
|
19
|
-
scanned_at: new Date().toISOString(),
|
|
20
|
-
files: [
|
|
21
|
-
{ path: "src/TrialLectureCommandServiceImpl.java", category: "source", language: "java", size_bytes: 2000 },
|
|
22
|
-
{ path: "src/LectureController.java", category: "source", language: "java", size_bytes: 1500 },
|
|
23
|
-
{ path: "test/TrialLectureTest.java", category: "test", language: "java", size_bytes: 1000 },
|
|
24
|
-
{ path: "schema/GT_CLASS.sql", category: "schema", language: "sql", size_bytes: 500 },
|
|
25
|
-
],
|
|
26
|
-
content_hashes: {},
|
|
27
|
-
dependency_graph: [
|
|
28
|
-
{ from: "src/LectureController.java", to: "src/TrialLectureCommandServiceImpl.java", kind: "import" },
|
|
29
|
-
],
|
|
30
|
-
api_patterns: [
|
|
31
|
-
{ file: "src/LectureController.java", method: "GET", path: "/trial/list", line: 30 },
|
|
32
|
-
],
|
|
33
|
-
schema_patterns: [
|
|
34
|
-
{ file: "schema/GT_CLASS.sql", table: "GT_CLASS", columns: "id, city, status", line: 1 },
|
|
35
|
-
],
|
|
36
|
-
config_patterns: [],
|
|
37
|
-
doc_structure: [],
|
|
38
|
-
};
|
|
39
|
-
// ─── Tests ───
|
|
40
|
-
describe("collectRelevantChunks", () => {
|
|
41
|
-
it("6관점 모두에서 결과를 생성한다", () => {
|
|
42
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험", "수업"]);
|
|
43
|
-
expect(result.by_viewpoint.semantics.length).toBeGreaterThan(0);
|
|
44
|
-
expect(result.by_viewpoint.dependency.length).toBeGreaterThan(0);
|
|
45
|
-
expect(result.coverage_gaps).toEqual([]); // 에이전트가 채움
|
|
46
|
-
expect(result.search_confidence.method).toBe("ontology");
|
|
47
|
-
});
|
|
48
|
-
it("total_chunks는 6관점 합계이다", () => {
|
|
49
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
|
|
50
|
-
const sum = Object.values(result.by_viewpoint).reduce((acc, chunks) => acc + chunks.length, 0);
|
|
51
|
-
expect(result.total_chunks).toBe(sum);
|
|
52
|
-
});
|
|
53
|
-
it("unresolved_count를 정확히 기록한다", () => {
|
|
54
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
|
|
55
|
-
expect(result.search_confidence.unresolved_count).toBe(1); // UnknownService
|
|
56
|
-
});
|
|
57
|
-
it("viewpoint_counts가 관점별 청크 수를 기록한다", () => {
|
|
58
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
|
|
59
|
-
for (const [vp, count] of Object.entries(result.search_confidence.viewpoint_counts)) {
|
|
60
|
-
expect(count).toBe(result.by_viewpoint[vp].length);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
it("viewpointOverrides로 특정 관점을 비활성화할 수 있다", () => {
|
|
64
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"], {
|
|
65
|
-
viewpointOverrides: { evolution: { enabled: false } },
|
|
66
|
-
});
|
|
67
|
-
expect(result.by_viewpoint.evolution).toEqual([]);
|
|
68
|
-
});
|
|
69
|
-
it("maxChunksPerViewpoint로 관점당 상한을 제어한다", () => {
|
|
70
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"], {
|
|
71
|
-
maxChunksPerViewpoint: 1,
|
|
72
|
-
});
|
|
73
|
-
for (const chunks of Object.values(result.by_viewpoint)) {
|
|
74
|
-
expect(chunks.length).toBeLessThanOrEqual(1);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
it("value_filters가 logic 관점에 반영된다", () => {
|
|
78
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
|
|
79
|
-
const logicContexts = result.by_viewpoint.logic.map((c) => c.context);
|
|
80
|
-
expect(logicContexts.some((ctx) => ctx.includes("PODO_TRIAL"))).toBe(true);
|
|
81
|
-
});
|
|
82
|
-
it("keywords_used가 기록된다", () => {
|
|
83
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험", "수업"]);
|
|
84
|
-
expect(result.search_confidence.keywords_used).toEqual(["체험", "수업"]);
|
|
85
|
-
});
|
|
86
|
-
it("guard_note가 있는 action이 logic 관점에 반영된다", () => {
|
|
87
|
-
const withGuard = {
|
|
88
|
-
...ONTOLOGY_RESULT,
|
|
89
|
-
related_actions: [{
|
|
90
|
-
id: "TRIAL-1",
|
|
91
|
-
display_name: "체험 수업 생성",
|
|
92
|
-
source_code: "TrialLectureCommandServiceImpl.create()",
|
|
93
|
-
guard_note: "체험 수업은 1회만 가능",
|
|
94
|
-
}],
|
|
95
|
-
};
|
|
96
|
-
const result = collectRelevantChunks(RESOLVED, withGuard, SCAN_RESULT, ["체험"]);
|
|
97
|
-
const logicChunks = result.by_viewpoint.logic;
|
|
98
|
-
expect(logicChunks.some((c) => c.context.includes("체험 수업은 1회만 가능"))).toBe(true);
|
|
99
|
-
// guard_note가 있는 청크는 실제 파일 경로를 가져야 함
|
|
100
|
-
const guardChunk = logicChunks.find((c) => c.context.includes("체험 수업은 1회만 가능"));
|
|
101
|
-
expect(guardChunk?.file_path).toBe("src/TrialLectureCommandServiceImpl.java");
|
|
102
|
-
});
|
|
103
|
-
it("preconditions가 있는 action이 logic 관점에 반영된다", () => {
|
|
104
|
-
const withPreconditions = {
|
|
105
|
-
...ONTOLOGY_RESULT,
|
|
106
|
-
related_actions: [{
|
|
107
|
-
id: "TRIAL-1",
|
|
108
|
-
display_name: "체험 수업 생성",
|
|
109
|
-
source_code: "TrialLectureCommandServiceImpl.create()",
|
|
110
|
-
preconditions: [{ check: "학생이 체험 수업을 받은 적 없음" }],
|
|
111
|
-
}],
|
|
112
|
-
};
|
|
113
|
-
const result = collectRelevantChunks(RESOLVED, withPreconditions, SCAN_RESULT, ["체험"]);
|
|
114
|
-
const logicChunks = result.by_viewpoint.logic;
|
|
115
|
-
expect(logicChunks.some((c) => c.context.includes("학생이 체험 수업을 받은 적 없음"))).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
it("value_filters의 search_hint가 file_path가 아닌 별도 필드에 저장된다", () => {
|
|
118
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
|
|
119
|
-
const vfChunks = result.by_viewpoint.logic.filter((c) => c.search_hint);
|
|
120
|
-
expect(vfChunks.length).toBeGreaterThan(0);
|
|
121
|
-
for (const c of vfChunks) {
|
|
122
|
-
expect(c.file_path).toBeUndefined(); // file_path 없이 search_hint만 사용
|
|
123
|
-
expect(c.search_hint).toMatch(/^grep:/);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
it("search_hint만 있는 청크는 토큰 추정에서 제외된다", () => {
|
|
127
|
-
const result = collectRelevantChunks(RESOLVED, ONTOLOGY_RESULT, SCAN_RESULT, ["체험"]);
|
|
128
|
-
// 빈 file_path는 uniqueFiles에 포함되지 않으므로 토큰 추정에 영향 없음
|
|
129
|
-
const allFilePaths = Object.values(result.by_viewpoint)
|
|
130
|
-
.flat()
|
|
131
|
-
.map((c) => c.file_path)
|
|
132
|
-
.filter((fp) => fp !== undefined);
|
|
133
|
-
const uniqueFiles = new Set(allFilePaths);
|
|
134
|
-
expect(result.total_tokens_estimate).toBe(uniqueFiles.size * 500);
|
|
135
|
-
});
|
|
136
|
-
});
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { readdirSync, statSync, readFileSync, existsSync } from "node:fs";
|
|
2
|
-
import { join, resolve, relative, extname } from "node:path";
|
|
3
|
-
import { contentHash } from "../scope-runtime/hash.js";
|
|
4
|
-
import { getLogger } from "../logger.js";
|
|
5
|
-
// ─── File Filtering ───
|
|
6
|
-
const ALWAYS_EXCLUDE_DIRS = new Set([".git", "node_modules", ".obsidian"]);
|
|
7
|
-
const BINARY_EXTENSIONS = new Set([
|
|
8
|
-
".png", ".jpg", ".jpeg", ".gif", ".bmp", ".ico", ".svg", ".webp",
|
|
9
|
-
".woff", ".woff2", ".ttf", ".otf", ".eot",
|
|
10
|
-
".zip", ".tar", ".gz", ".bz2", ".7z", ".rar",
|
|
11
|
-
".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx",
|
|
12
|
-
".exe", ".dll", ".so", ".dylib", ".class", ".jar", ".war",
|
|
13
|
-
".o", ".obj", ".pyc", ".pyo",
|
|
14
|
-
".mp3", ".mp4", ".avi", ".mov", ".flv", ".wav",
|
|
15
|
-
".sqlite", ".db",
|
|
16
|
-
]);
|
|
17
|
-
export function isBinaryFile(filePath) {
|
|
18
|
-
if (BINARY_EXTENSIONS.has(extname(filePath).toLowerCase())) {
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
try {
|
|
22
|
-
const buf = Buffer.alloc(512);
|
|
23
|
-
const fd = require("node:fs").openSync(filePath, "r");
|
|
24
|
-
const bytesRead = require("node:fs").readSync(fd, buf, 0, 512, 0);
|
|
25
|
-
require("node:fs").closeSync(fd);
|
|
26
|
-
for (let i = 0; i < bytesRead; i++) {
|
|
27
|
-
if (buf[i] === 0)
|
|
28
|
-
return true; // NULL byte = binary
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
catch {
|
|
33
|
-
return false;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
// ─── .gitignore parsing (simplified) ───
|
|
37
|
-
export function loadGitignorePatterns(dirPath) {
|
|
38
|
-
const gitignorePath = join(dirPath, ".gitignore");
|
|
39
|
-
if (!existsSync(gitignorePath))
|
|
40
|
-
return [];
|
|
41
|
-
try {
|
|
42
|
-
return readFileSync(gitignorePath, "utf-8")
|
|
43
|
-
.split("\n")
|
|
44
|
-
.map(line => line.trim())
|
|
45
|
-
.filter(line => line.length > 0 && !line.startsWith("#"));
|
|
46
|
-
}
|
|
47
|
-
catch {
|
|
48
|
-
return [];
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
function matchesGitignore(relativePath, patterns) {
|
|
52
|
-
let excluded = false;
|
|
53
|
-
for (const pattern of patterns) {
|
|
54
|
-
// Negation pattern: ! prefix → force include (cancel previous exclusion)
|
|
55
|
-
const isNegation = pattern.startsWith("!");
|
|
56
|
-
const rawPattern = isNegation ? pattern.slice(1) : pattern;
|
|
57
|
-
const cleanPattern = rawPattern.endsWith("/") ? rawPattern.slice(0, -1) : rawPattern;
|
|
58
|
-
let matched = false;
|
|
59
|
-
// Simple matching: exact segment match
|
|
60
|
-
const segments = relativePath.split("/");
|
|
61
|
-
for (const seg of segments) {
|
|
62
|
-
if (seg === cleanPattern) {
|
|
63
|
-
matched = true;
|
|
64
|
-
break;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
// Wildcard patterns: *.ext
|
|
68
|
-
if (!matched && cleanPattern.startsWith("*.")) {
|
|
69
|
-
const ext = cleanPattern.slice(1);
|
|
70
|
-
if (relativePath.endsWith(ext)) {
|
|
71
|
-
matched = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
// Path prefix match (e.g. "dist/keep.js" matches pattern "dist/keep.js")
|
|
75
|
-
if (!matched && cleanPattern.includes("/")) {
|
|
76
|
-
if (relativePath === cleanPattern || relativePath.startsWith(cleanPattern + "/")) {
|
|
77
|
-
matched = true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (matched) {
|
|
81
|
-
excluded = isNegation ? false : true;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return excluded;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Check if any negation pattern references a path under the given directory.
|
|
88
|
-
* Used to decide whether to recurse into an otherwise-excluded directory.
|
|
89
|
-
*/
|
|
90
|
-
function hasNegationUnder(dirRelPath, patterns) {
|
|
91
|
-
for (const pattern of patterns) {
|
|
92
|
-
if (!pattern.startsWith("!"))
|
|
93
|
-
continue;
|
|
94
|
-
const rawPattern = pattern.slice(1);
|
|
95
|
-
const cleanPattern = rawPattern.endsWith("/") ? rawPattern.slice(0, -1) : rawPattern;
|
|
96
|
-
if (cleanPattern.startsWith(dirRelPath + "/")) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
// ─── Path normalization (NFC) ───
|
|
103
|
-
export function normalizePath(p) {
|
|
104
|
-
return resolve(p).normalize("NFC");
|
|
105
|
-
}
|
|
106
|
-
export function walkDirectory(rootPath, options = {}) {
|
|
107
|
-
const root = normalizePath(rootPath);
|
|
108
|
-
const results = [];
|
|
109
|
-
const extraExclude = options.extraExcludeDirs ?? new Set();
|
|
110
|
-
const gitignore = options.gitignorePatterns ?? loadGitignorePatterns(root);
|
|
111
|
-
function walk(dirPath) {
|
|
112
|
-
let entries;
|
|
113
|
-
try {
|
|
114
|
-
entries = readdirSync(dirPath);
|
|
115
|
-
}
|
|
116
|
-
catch (error) {
|
|
117
|
-
getLogger().debug("walkDirectory: failed to read directory", { path: dirPath, error });
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
for (const name of entries) {
|
|
121
|
-
const fullPath = join(dirPath, name);
|
|
122
|
-
const relPath = relative(root, fullPath).normalize("NFC");
|
|
123
|
-
// Skip excluded directories
|
|
124
|
-
if (ALWAYS_EXCLUDE_DIRS.has(name) || extraExclude.has(name)) {
|
|
125
|
-
continue;
|
|
126
|
-
}
|
|
127
|
-
const excluded = matchesGitignore(relPath, gitignore);
|
|
128
|
-
let stat;
|
|
129
|
-
try {
|
|
130
|
-
stat = statSync(fullPath);
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
getLogger().debug("walkDirectory: failed to stat file", { path: fullPath, error });
|
|
134
|
-
continue; // broken symlink etc.
|
|
135
|
-
}
|
|
136
|
-
if (stat.isDirectory()) {
|
|
137
|
-
// Even if the directory is excluded, recurse if negation patterns
|
|
138
|
-
// reference paths under it — individual files will be checked.
|
|
139
|
-
if (excluded && !hasNegationUnder(relPath, gitignore)) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
walk(fullPath);
|
|
143
|
-
}
|
|
144
|
-
else if (excluded) {
|
|
145
|
-
// File is excluded by gitignore
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
else if (stat.isFile()) {
|
|
149
|
-
// Skip binary files
|
|
150
|
-
if (isBinaryFile(fullPath))
|
|
151
|
-
continue;
|
|
152
|
-
results.push({
|
|
153
|
-
path: relPath,
|
|
154
|
-
category: categorizeFile(relPath),
|
|
155
|
-
language: detectLanguage(relPath),
|
|
156
|
-
size_bytes: stat.size,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
// Symlinks: statSync follows them by default. Circular symlinks
|
|
160
|
-
// will fail with ELOOP and be caught by the try/catch.
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
walk(root);
|
|
164
|
-
return results;
|
|
165
|
-
}
|
|
166
|
-
// ─── Sorted concat hash ───
|
|
167
|
-
/**
|
|
168
|
-
* Core hash logic: sorted path-hash pairs → single directory hash.
|
|
169
|
-
* Both computeDirectoryHash and computeDirectoryHashFromMap delegate to this.
|
|
170
|
-
* Changing this function changes all directory hashes (source_hashes in events).
|
|
171
|
-
*/
|
|
172
|
-
export function computeHashFromEntries(entries) {
|
|
173
|
-
const sorted = [...entries].sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
174
|
-
return contentHash(sorted.map(e => e[1]).join(""));
|
|
175
|
-
}
|
|
176
|
-
export function computeDirectoryHash(rootPath, files) {
|
|
177
|
-
const root = normalizePath(rootPath);
|
|
178
|
-
const entries = [];
|
|
179
|
-
for (const file of files) {
|
|
180
|
-
const fullPath = join(root, file.path);
|
|
181
|
-
try {
|
|
182
|
-
const content = readFileSync(fullPath, "utf-8");
|
|
183
|
-
entries.push([file.path, contentHash(content)]);
|
|
184
|
-
}
|
|
185
|
-
catch {
|
|
186
|
-
entries.push([file.path, "unreadable"]);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return computeHashFromEntries(entries);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Compute directory hash from pre-computed content hashes.
|
|
193
|
-
* Avoids re-reading files when hashes are already available.
|
|
194
|
-
* Results are identical to computeDirectoryHash for the same file set.
|
|
195
|
-
*/
|
|
196
|
-
export function computeDirectoryHashFromMap(contentMap) {
|
|
197
|
-
const entries = [...contentMap.entries()];
|
|
198
|
-
return computeHashFromEntries(entries);
|
|
199
|
-
}
|
|
200
|
-
// ─── File categorization ───
|
|
201
|
-
const LANGUAGE_MAP = {
|
|
202
|
-
".ts": "typescript", ".tsx": "typescript", ".mts": "typescript", ".cts": "typescript",
|
|
203
|
-
".js": "javascript", ".jsx": "javascript", ".mjs": "javascript", ".cjs": "javascript",
|
|
204
|
-
".java": "java", ".kt": "kotlin", ".kts": "kotlin",
|
|
205
|
-
".py": "python", ".go": "go", ".rs": "rust", ".rb": "ruby",
|
|
206
|
-
".sql": "sql",
|
|
207
|
-
".yaml": "yaml", ".yml": "yaml",
|
|
208
|
-
".json": "json",
|
|
209
|
-
".md": "markdown",
|
|
210
|
-
".html": "html", ".css": "css", ".scss": "scss",
|
|
211
|
-
".sh": "shell", ".bash": "shell",
|
|
212
|
-
".xml": "xml",
|
|
213
|
-
".toml": "toml",
|
|
214
|
-
".gradle": "gradle",
|
|
215
|
-
};
|
|
216
|
-
function detectLanguage(filePath) {
|
|
217
|
-
const ext = extname(filePath).toLowerCase();
|
|
218
|
-
return LANGUAGE_MAP[ext];
|
|
219
|
-
}
|
|
220
|
-
const TEST_PATTERNS = [/\.test\.[^.]+$/, /\.spec\.[^.]+$/, /\/__tests__\//, /\/test\//];
|
|
221
|
-
const CONFIG_PATTERNS = [
|
|
222
|
-
/\.env/, /\.config\.[^.]+$/, /tsconfig/, /package\.json$/, /\.eslintrc/,
|
|
223
|
-
/application\.ya?ml$/, /application\.properties$/,
|
|
224
|
-
];
|
|
225
|
-
const SCHEMA_PATTERNS = [/\.sql$/, /migration/, /schema/, /\.dbml$/];
|
|
226
|
-
const DOC_PATTERNS = [/\.md$/, /\.mdx$/, /README/, /CHANGELOG/];
|
|
227
|
-
function categorizeFile(relPath) {
|
|
228
|
-
if (TEST_PATTERNS.some(p => p.test(relPath)))
|
|
229
|
-
return "test";
|
|
230
|
-
if (CONFIG_PATTERNS.some(p => p.test(relPath)))
|
|
231
|
-
return "config";
|
|
232
|
-
if (SCHEMA_PATTERNS.some(p => p.test(relPath)))
|
|
233
|
-
return "schema";
|
|
234
|
-
if (DOC_PATTERNS.some(p => p.test(relPath)))
|
|
235
|
-
return "doc";
|
|
236
|
-
const lang = detectLanguage(relPath);
|
|
237
|
-
if (lang && !["yaml", "json", "markdown", "xml", "toml"].includes(lang))
|
|
238
|
-
return "source";
|
|
239
|
-
return "other";
|
|
240
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
2
|
-
import { mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { walkDirectory, computeDirectoryHash, normalizePath, isBinaryFile } from "./file-utils.js";
|
|
5
|
-
const TMP = join(import.meta.dirname ?? ".", ".tmp-fileutils-test");
|
|
6
|
-
beforeEach(() => mkdirSync(TMP, { recursive: true }));
|
|
7
|
-
afterEach(() => rmSync(TMP, { recursive: true, force: true }));
|
|
8
|
-
describe("walkDirectory", () => {
|
|
9
|
-
it("lists files recursively", () => {
|
|
10
|
-
mkdirSync(join(TMP, "sub"), { recursive: true });
|
|
11
|
-
writeFileSync(join(TMP, "a.ts"), "const a = 1;");
|
|
12
|
-
writeFileSync(join(TMP, "sub", "b.ts"), "const b = 2;");
|
|
13
|
-
const files = walkDirectory(TMP);
|
|
14
|
-
const paths = files.map(f => f.path).sort();
|
|
15
|
-
expect(paths).toEqual(["a.ts", "sub/b.ts"]);
|
|
16
|
-
});
|
|
17
|
-
it("excludes .git directory", () => {
|
|
18
|
-
mkdirSync(join(TMP, ".git", "objects"), { recursive: true });
|
|
19
|
-
writeFileSync(join(TMP, ".git", "config"), "gitconfig");
|
|
20
|
-
writeFileSync(join(TMP, "app.ts"), "code");
|
|
21
|
-
const files = walkDirectory(TMP);
|
|
22
|
-
expect(files.map(f => f.path)).toEqual(["app.ts"]);
|
|
23
|
-
});
|
|
24
|
-
it("excludes node_modules", () => {
|
|
25
|
-
mkdirSync(join(TMP, "node_modules", "pkg"), { recursive: true });
|
|
26
|
-
writeFileSync(join(TMP, "node_modules", "pkg", "index.js"), "code");
|
|
27
|
-
writeFileSync(join(TMP, "app.ts"), "code");
|
|
28
|
-
const files = walkDirectory(TMP);
|
|
29
|
-
expect(files.map(f => f.path)).toEqual(["app.ts"]);
|
|
30
|
-
});
|
|
31
|
-
it("respects .gitignore", () => {
|
|
32
|
-
writeFileSync(join(TMP, ".gitignore"), "dist\n*.log\n");
|
|
33
|
-
mkdirSync(join(TMP, "dist"), { recursive: true });
|
|
34
|
-
writeFileSync(join(TMP, "dist", "bundle.js"), "bundled");
|
|
35
|
-
writeFileSync(join(TMP, "app.log"), "log");
|
|
36
|
-
writeFileSync(join(TMP, "app.ts"), "code");
|
|
37
|
-
const files = walkDirectory(TMP);
|
|
38
|
-
const paths = files.map(f => f.path).filter(p => p !== ".gitignore");
|
|
39
|
-
expect(paths).toEqual(["app.ts"]);
|
|
40
|
-
});
|
|
41
|
-
it("skips binary files", () => {
|
|
42
|
-
writeFileSync(join(TMP, "app.ts"), "code");
|
|
43
|
-
writeFileSync(join(TMP, "image.png"), Buffer.from([0x89, 0x50, 0x4e, 0x47]));
|
|
44
|
-
const files = walkDirectory(TMP);
|
|
45
|
-
expect(files.map(f => f.path)).toEqual(["app.ts"]);
|
|
46
|
-
});
|
|
47
|
-
it("categorizes files", () => {
|
|
48
|
-
writeFileSync(join(TMP, "app.ts"), "code");
|
|
49
|
-
writeFileSync(join(TMP, "app.test.ts"), "test");
|
|
50
|
-
writeFileSync(join(TMP, "README.md"), "docs");
|
|
51
|
-
writeFileSync(join(TMP, ".env"), "KEY=val");
|
|
52
|
-
const files = walkDirectory(TMP);
|
|
53
|
-
const cats = Object.fromEntries(files.map(f => [f.path, f.category]));
|
|
54
|
-
expect(cats["app.ts"]).toBe("source");
|
|
55
|
-
expect(cats["app.test.ts"]).toBe("test");
|
|
56
|
-
expect(cats["README.md"]).toBe("doc");
|
|
57
|
-
expect(cats[".env"]).toBe("config");
|
|
58
|
-
});
|
|
59
|
-
it("handles empty directory", () => {
|
|
60
|
-
expect(walkDirectory(TMP)).toEqual([]);
|
|
61
|
-
});
|
|
62
|
-
it("excludes extra dirs", () => {
|
|
63
|
-
mkdirSync(join(TMP, ".obsidian"), { recursive: true });
|
|
64
|
-
writeFileSync(join(TMP, ".obsidian", "config.json"), "{}");
|
|
65
|
-
writeFileSync(join(TMP, "note.md"), "# Note");
|
|
66
|
-
const files = walkDirectory(TMP);
|
|
67
|
-
expect(files.map(f => f.path)).toEqual(["note.md"]);
|
|
68
|
-
});
|
|
69
|
-
it("respects .gitignore negation pattern (! prefix)", () => {
|
|
70
|
-
writeFileSync(join(TMP, ".gitignore"), "*.log\n!important.log\n");
|
|
71
|
-
writeFileSync(join(TMP, "debug.log"), "debug info");
|
|
72
|
-
writeFileSync(join(TMP, "important.log"), "important info");
|
|
73
|
-
writeFileSync(join(TMP, "app.ts"), "code");
|
|
74
|
-
const files = walkDirectory(TMP);
|
|
75
|
-
const paths = files.map(f => f.path).filter(p => p !== ".gitignore").sort();
|
|
76
|
-
expect(paths).toContain("important.log");
|
|
77
|
-
expect(paths).toContain("app.ts");
|
|
78
|
-
expect(paths).not.toContain("debug.log");
|
|
79
|
-
});
|
|
80
|
-
it("respects .gitignore negation for directory paths", () => {
|
|
81
|
-
writeFileSync(join(TMP, ".gitignore"), "dist\n!dist/keep.js\n");
|
|
82
|
-
mkdirSync(join(TMP, "dist"), { recursive: true });
|
|
83
|
-
writeFileSync(join(TMP, "dist", "bundle.js"), "bundled");
|
|
84
|
-
writeFileSync(join(TMP, "dist", "keep.js"), "kept");
|
|
85
|
-
writeFileSync(join(TMP, "app.ts"), "code");
|
|
86
|
-
const files = walkDirectory(TMP);
|
|
87
|
-
const paths = files.map(f => f.path).filter(p => p !== ".gitignore").sort();
|
|
88
|
-
expect(paths).toContain("dist/keep.js");
|
|
89
|
-
expect(paths).toContain("app.ts");
|
|
90
|
-
expect(paths).not.toContain("dist/bundle.js");
|
|
91
|
-
});
|
|
92
|
-
it("handles Korean filenames with NFC normalization", () => {
|
|
93
|
-
writeFileSync(join(TMP, "컴포넌트.tsx"), "export default {}");
|
|
94
|
-
const files = walkDirectory(TMP);
|
|
95
|
-
expect(files).toHaveLength(1);
|
|
96
|
-
expect(files[0].path).toBe("컴포넌트.tsx");
|
|
97
|
-
expect(files[0].language).toBe("typescript");
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
describe("computeDirectoryHash", () => {
|
|
101
|
-
it("produces consistent hash for same content", () => {
|
|
102
|
-
writeFileSync(join(TMP, "a.ts"), "const a = 1;");
|
|
103
|
-
writeFileSync(join(TMP, "b.ts"), "const b = 2;");
|
|
104
|
-
const files = walkDirectory(TMP);
|
|
105
|
-
const h1 = computeDirectoryHash(TMP, files);
|
|
106
|
-
const h2 = computeDirectoryHash(TMP, files);
|
|
107
|
-
expect(h1).toBe(h2);
|
|
108
|
-
});
|
|
109
|
-
it("changes when file content changes", () => {
|
|
110
|
-
writeFileSync(join(TMP, "a.ts"), "const a = 1;");
|
|
111
|
-
const files1 = walkDirectory(TMP);
|
|
112
|
-
const h1 = computeDirectoryHash(TMP, files1);
|
|
113
|
-
writeFileSync(join(TMP, "a.ts"), "const a = 2;");
|
|
114
|
-
const h2 = computeDirectoryHash(TMP, files1); // same file list
|
|
115
|
-
expect(h1).not.toBe(h2);
|
|
116
|
-
});
|
|
117
|
-
it("changes when file is added", () => {
|
|
118
|
-
writeFileSync(join(TMP, "a.ts"), "code");
|
|
119
|
-
const files1 = walkDirectory(TMP);
|
|
120
|
-
const h1 = computeDirectoryHash(TMP, files1);
|
|
121
|
-
writeFileSync(join(TMP, "b.ts"), "code2");
|
|
122
|
-
const files2 = walkDirectory(TMP);
|
|
123
|
-
const h2 = computeDirectoryHash(TMP, files2);
|
|
124
|
-
expect(h1).not.toBe(h2);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
describe("normalizePath", () => {
|
|
128
|
-
it("resolves relative paths", () => {
|
|
129
|
-
const p = normalizePath("./src/../src/app.ts");
|
|
130
|
-
expect(p).not.toContain("..");
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe("isBinaryFile", () => {
|
|
134
|
-
it("detects by extension", () => {
|
|
135
|
-
writeFileSync(join(TMP, "test.png"), "fakepng");
|
|
136
|
-
expect(isBinaryFile(join(TMP, "test.png"))).toBe(true);
|
|
137
|
-
});
|
|
138
|
-
it("detects by null byte", () => {
|
|
139
|
-
writeFileSync(join(TMP, "test.dat"), Buffer.from([0x48, 0x65, 0x00, 0x6c]));
|
|
140
|
-
expect(isBinaryFile(join(TMP, "test.dat"))).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
it("text files are not binary", () => {
|
|
143
|
-
writeFileSync(join(TMP, "test.ts"), "const x = 1;");
|
|
144
|
-
expect(isBinaryFile(join(TMP, "test.ts"))).toBe(false);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provisional term 인용 금지 검증 도구 (W-D-02, D0 Bootstrap).
|
|
3
|
-
*
|
|
4
|
-
* core-lexicon.yaml 의 provisional_lifecycle 규칙에 따라,
|
|
5
|
-
* lifecycle_status 가 seed/candidate/provisional 인 term 을
|
|
6
|
-
* authority file 이외의 문서·코드에서 인용하면 warn 또는 reject 한다.
|
|
7
|
-
*
|
|
8
|
-
* authority file (core-lexicon.yaml 자체) 내 참조는 예외 (bypass).
|
|
9
|
-
*/
|
|
10
|
-
import { readFileSync } from "node:fs";
|
|
11
|
-
import { resolve, basename } from "node:path";
|
|
12
|
-
import { parse as yamlParse } from "yaml";
|
|
13
|
-
// lifecycle_status 값 중 인용이 금지되는 상태
|
|
14
|
-
const CITATION_BLOCKED_STATUSES = new Set(["seed", "candidate", "provisional"]);
|
|
15
|
-
// authority file — 이 파일 내 참조는 예외
|
|
16
|
-
const AUTHORITY_FILE = "core-lexicon.yaml";
|
|
17
|
-
// ─── Lexicon 읽기 ───
|
|
18
|
-
/**
|
|
19
|
-
* core-lexicon.yaml 에서 provisional_terms section 의 term 목록을 읽는다.
|
|
20
|
-
* provisional_terms section 이 없으면 빈 배열을 반환한다.
|
|
21
|
-
*/
|
|
22
|
-
export function loadProvisionalTerms(lexiconPath) {
|
|
23
|
-
const content = readFileSync(resolve(lexiconPath), "utf-8");
|
|
24
|
-
const data = yamlParse(content);
|
|
25
|
-
const provisionalTerms = data["provisional_terms"];
|
|
26
|
-
if (!provisionalTerms || typeof provisionalTerms !== "object") {
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
return Object.entries(provisionalTerms)
|
|
30
|
-
.filter(([_, entry]) => entry && typeof entry === "object" && entry.lifecycle_status)
|
|
31
|
-
.map(([termId, entry]) => ({
|
|
32
|
-
term_id: termId,
|
|
33
|
-
lifecycle_status: entry.lifecycle_status,
|
|
34
|
-
}));
|
|
35
|
-
}
|
|
36
|
-
// ─── 검증 ───
|
|
37
|
-
/**
|
|
38
|
-
* 단일 파일의 내용에서 provisional term 인용을 검사한다.
|
|
39
|
-
*
|
|
40
|
-
* @param filePath - 검사 대상 파일 경로
|
|
41
|
-
* @param fileContent - 파일 내용 문자열
|
|
42
|
-
* @param terms - provisional term 목록
|
|
43
|
-
* @param options - severity 설정 (기본 warn)
|
|
44
|
-
* @returns 발견된 위반 목록
|
|
45
|
-
*/
|
|
46
|
-
export function checkFileCitations(filePath, fileContent, terms, options = {}) {
|
|
47
|
-
const severity = options.severity ?? "warn";
|
|
48
|
-
// authority file bypass
|
|
49
|
-
if (basename(filePath) === AUTHORITY_FILE) {
|
|
50
|
-
return [];
|
|
51
|
-
}
|
|
52
|
-
const violations = [];
|
|
53
|
-
const lines = fileContent.split("\n");
|
|
54
|
-
for (const term of terms) {
|
|
55
|
-
if (!CITATION_BLOCKED_STATUSES.has(term.lifecycle_status)) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
// term_id를 단어 경계로 검색 (부분 매칭 방지)
|
|
59
|
-
const pattern = new RegExp(`\\b${escapeRegex(term.term_id)}\\b`, "g");
|
|
60
|
-
for (let i = 0; i < lines.length; i++) {
|
|
61
|
-
if (pattern.test(lines[i])) {
|
|
62
|
-
violations.push({
|
|
63
|
-
file: filePath,
|
|
64
|
-
line: i + 1,
|
|
65
|
-
term_id: term.term_id,
|
|
66
|
-
lifecycle_status: term.lifecycle_status,
|
|
67
|
-
severity,
|
|
68
|
-
message: `provisional term "${term.term_id}" (status: ${term.lifecycle_status}) 인용 금지 — promoted 전이 후 사용 가능`,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
// reset regex lastIndex for next line
|
|
72
|
-
pattern.lastIndex = 0;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return violations;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 복수 파일을 검사하고 전체 위반 목록을 반환한다.
|
|
79
|
-
*/
|
|
80
|
-
export function checkMultipleFiles(files, terms, options = {}) {
|
|
81
|
-
return files.flatMap((f) => checkFileCitations(f.path, f.content, terms, options));
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* 위반 목록에 reject severity 가 1건 이상 있으면 true.
|
|
85
|
-
* pre-commit hook 에서 exit code 결정에 사용.
|
|
86
|
-
*/
|
|
87
|
-
export function hasRejectViolations(violations) {
|
|
88
|
-
return violations.some((v) => v.severity === "reject");
|
|
89
|
-
}
|
|
90
|
-
// ─── Helpers ───
|
|
91
|
-
function escapeRegex(str) {
|
|
92
|
-
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
93
|
-
}
|