novelws 1.2.0
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/CHANGELOG.md +161 -0
- package/LICENSE +22 -0
- package/README.md +372 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +50 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/check.d.ts +6 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +32 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/init.d.ts +6 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +160 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/plugin.d.ts +6 -0
- package/dist/commands/plugin.d.ts.map +1 -0
- package/dist/commands/plugin.js +135 -0
- package/dist/commands/plugin.js.map +1 -0
- package/dist/commands/upgrade.d.ts +6 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +92 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/core/config.d.ts +72 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +136 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/errors.d.ts +59 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +125 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/platform.d.ts +27 -0
- package/dist/core/platform.d.ts.map +1 -0
- package/dist/core/platform.js +75 -0
- package/dist/core/platform.js.map +1 -0
- package/dist/core/template.d.ts +35 -0
- package/dist/core/template.d.ts.map +1 -0
- package/dist/core/template.js +94 -0
- package/dist/core/template.js.map +1 -0
- package/dist/plugins/identifier.d.ts +13 -0
- package/dist/plugins/identifier.d.ts.map +1 -0
- package/dist/plugins/identifier.js +72 -0
- package/dist/plugins/identifier.js.map +1 -0
- package/dist/plugins/installers/base.d.ts +27 -0
- package/dist/plugins/installers/base.d.ts.map +1 -0
- package/dist/plugins/installers/base.js +30 -0
- package/dist/plugins/installers/base.js.map +1 -0
- package/dist/plugins/installers/github.d.ts +22 -0
- package/dist/plugins/installers/github.d.ts.map +1 -0
- package/dist/plugins/installers/github.js +133 -0
- package/dist/plugins/installers/github.js.map +1 -0
- package/dist/plugins/installers/local.d.ts +16 -0
- package/dist/plugins/installers/local.d.ts.map +1 -0
- package/dist/plugins/installers/local.js +69 -0
- package/dist/plugins/installers/local.js.map +1 -0
- package/dist/plugins/installers/npm.d.ts +20 -0
- package/dist/plugins/installers/npm.d.ts.map +1 -0
- package/dist/plugins/installers/npm.js +99 -0
- package/dist/plugins/installers/npm.js.map +1 -0
- package/dist/plugins/manager.d.ts +77 -0
- package/dist/plugins/manager.d.ts.map +1 -0
- package/dist/plugins/manager.js +349 -0
- package/dist/plugins/manager.js.map +1 -0
- package/dist/plugins/registry.d.ts +48 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +111 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/types.d.ts +66 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +2 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/plugins/validator.d.ts +19 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +164 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/utils/logger.d.ts +13 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +48 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/project.d.ts +24 -0
- package/dist/utils/project.d.ts.map +1 -0
- package/dist/utils/project.js +61 -0
- package/dist/utils/project.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +21 -0
- package/dist/version.js.map +1 -0
- package/package.json +76 -0
- package/plugins/authentic-voice/README.md +31 -0
- package/plugins/authentic-voice/commands/authentic-voice.md +73 -0
- package/plugins/authentic-voice/commands/authenticity-audit.md +37 -0
- package/plugins/authentic-voice/config.yaml +30 -0
- package/plugins/authentic-voice/experts/authentic-editor.md +27 -0
- package/plugins/export/README.md +319 -0
- package/plugins/export/commands/export.md +460 -0
- package/plugins/export/commands/generate-cover.md +256 -0
- package/plugins/export/commands/metadata.md +309 -0
- package/plugins/export/config.yaml +47 -0
- package/plugins/export/experts/publishing-expert.md +171 -0
- package/plugins/export/templates/epub/chapter-template.html +13 -0
- package/plugins/export/templates/epub/cover-template.html +14 -0
- package/plugins/export/templates/epub/stylesheet.css +200 -0
- package/plugins/export/templates/pdf/ebook-style.css +137 -0
- package/plugins/export/templates/pdf/print-style.css +179 -0
- package/plugins/export/templates/platforms/jinjiang-format.md +101 -0
- package/plugins/export/templates/platforms/qidian-format.md +108 -0
- package/plugins/export/templates/platforms/tomato-format.md +95 -0
- package/plugins/translate/README.md +265 -0
- package/plugins/translate/commands/glossary.md +731 -0
- package/plugins/translate/commands/translate-preview.md +543 -0
- package/plugins/translate/commands/translate.md +649 -0
- package/plugins/translate/config.yaml +43 -0
- package/plugins/translate/experts/literary-translator.md +605 -0
- package/templates/commands/analyze.md +1485 -0
- package/templates/commands/checklist.md +434 -0
- package/templates/commands/clarify.md +257 -0
- package/templates/commands/constitution.md +257 -0
- package/templates/commands/expert.md +136 -0
- package/templates/commands/plan.md +749 -0
- package/templates/commands/recap.md +613 -0
- package/templates/commands/relations.md +96 -0
- package/templates/commands/revise.md +341 -0
- package/templates/commands/specify.md +682 -0
- package/templates/commands/tasks.md +142 -0
- package/templates/commands/timeline.md +73 -0
- package/templates/commands/track-init.md +137 -0
- package/templates/commands/track.md +463 -0
- package/templates/commands/write.md +1264 -0
- package/templates/config/keyword-mappings.json +106 -0
- package/templates/knowledge/audit-config.json +26 -0
- package/templates/knowledge/character-profiles.md +152 -0
- package/templates/knowledge/character-voices.md +137 -0
- package/templates/knowledge/locations.md +184 -0
- package/templates/knowledge/world-setting.md +121 -0
- package/templates/knowledge-base/README.md +285 -0
- package/templates/knowledge-base/character-archetypes/01-hero.md +233 -0
- package/templates/knowledge-base/character-archetypes/02-mentor.md +177 -0
- package/templates/knowledge-base/character-archetypes/03-shadow.md +221 -0
- package/templates/knowledge-base/character-archetypes/04-ally.md +178 -0
- package/templates/knowledge-base/character-archetypes/05-shapeshifter.md +177 -0
- package/templates/knowledge-base/character-archetypes/06-trickster.md +181 -0
- package/templates/knowledge-base/character-archetypes/07-threshold-guardian.md +177 -0
- package/templates/knowledge-base/character-archetypes/08-herald.md +180 -0
- package/templates/knowledge-base/character-archetypes/09-father.md +249 -0
- package/templates/knowledge-base/character-archetypes/10-mother.md +202 -0
- package/templates/knowledge-base/character-archetypes/11-child.md +183 -0
- package/templates/knowledge-base/character-archetypes/12-sage.md +202 -0
- package/templates/knowledge-base/character-archetypes/README.md +60 -0
- package/templates/knowledge-base/character-archetypes/application-guide.md +222 -0
- package/templates/knowledge-base/character-archetypes/archetype-combinations.md +242 -0
- package/templates/knowledge-base/character-archetypes/config.yaml +28 -0
- package/templates/knowledge-base/character-archetypes/examples-analysis.md +223 -0
- package/templates/knowledge-base/craft/character-arc.md +1153 -0
- package/templates/knowledge-base/craft/dialogue.md +1170 -0
- package/templates/knowledge-base/craft/pacing.md +1200 -0
- package/templates/knowledge-base/craft/scene-structure.md +1136 -0
- package/templates/knowledge-base/craft/show-not-tell.md +1012 -0
- package/templates/knowledge-base/emotional-beats/01-first-meeting.md +145 -0
- package/templates/knowledge-base/emotional-beats/02-bonding-moment.md +226 -0
- package/templates/knowledge-base/emotional-beats/03-declaration.md +284 -0
- package/templates/knowledge-base/emotional-beats/04-triumph.md +240 -0
- package/templates/knowledge-base/emotional-beats/05-reunion.md +396 -0
- package/templates/knowledge-base/emotional-beats/06-forgiveness.md +204 -0
- package/templates/knowledge-base/emotional-beats/07-betrayal.md +204 -0
- package/templates/knowledge-base/emotional-beats/08-loss.md +214 -0
- package/templates/knowledge-base/emotional-beats/09-rejection.md +254 -0
- package/templates/knowledge-base/emotional-beats/10-failure.md +244 -0
- package/templates/knowledge-base/emotional-beats/11-misunderstanding.md +205 -0
- package/templates/knowledge-base/emotional-beats/12-farewell.md +283 -0
- package/templates/knowledge-base/emotional-beats/13-revelation.md +242 -0
- package/templates/knowledge-base/emotional-beats/14-point-of-no-return.md +215 -0
- package/templates/knowledge-base/emotional-beats/15-dark-night.md +244 -0
- package/templates/knowledge-base/emotional-beats/16-sacrifice.md +246 -0
- package/templates/knowledge-base/emotional-beats/17-awakening.md +246 -0
- package/templates/knowledge-base/emotional-beats/18-confrontation.md +217 -0
- package/templates/knowledge-base/emotional-beats/19-bittersweet-goodbye.md +368 -0
- package/templates/knowledge-base/emotional-beats/20-moral-dilemma.md +248 -0
- package/templates/knowledge-base/emotional-beats/21-temptation.md +240 -0
- package/templates/knowledge-base/emotional-beats/22-redemption.md +210 -0
- package/templates/knowledge-base/emotional-beats/README.md +104 -0
- package/templates/knowledge-base/emotional-beats/beat-sequences.md +276 -0
- package/templates/knowledge-base/emotional-beats/config.yaml +30 -0
- package/templates/knowledge-base/emotional-beats/pacing-guide.md +390 -0
- package/templates/knowledge-base/genres/historical.md +1127 -0
- package/templates/knowledge-base/genres/mystery.md +1123 -0
- package/templates/knowledge-base/genres/revenge.md +846 -0
- package/templates/knowledge-base/genres/romance.md +948 -0
- package/templates/knowledge-base/genres/sci-fi.md +156 -0
- package/templates/knowledge-base/genres/thriller.md +166 -0
- package/templates/knowledge-base/genres/wuxia.md +143 -0
- package/templates/knowledge-base/references/README.md +96 -0
- package/templates/knowledge-base/references/china-1920s/culture.md +423 -0
- package/templates/knowledge-base/references/china-1920s/daily-life.md +616 -0
- package/templates/knowledge-base/references/china-1920s/overview.md +298 -0
- package/templates/knowledge-base/references/china-1920s/society.md +703 -0
- package/templates/knowledge-base/references/china-1920s/warlords.md +427 -0
- package/templates/knowledge-base/references/cultivation-world/daily-life.md +108 -0
- package/templates/knowledge-base/references/cultivation-world/overview.md +64 -0
- package/templates/knowledge-base/references/cultivation-world/power-system.md +108 -0
- package/templates/knowledge-base/references/cultivation-world/sects.md +104 -0
- package/templates/knowledge-base/references/cultivation-world/world-setting.md +108 -0
- package/templates/knowledge-base/references/modern-workplace/corporate.md +115 -0
- package/templates/knowledge-base/references/modern-workplace/daily-life.md +129 -0
- package/templates/knowledge-base/references/modern-workplace/overview.md +73 -0
- package/templates/knowledge-base/references/modern-workplace/relationships.md +107 -0
- package/templates/knowledge-base/references/modern-workplace/tech-industry.md +131 -0
- package/templates/knowledge-base/references/tang-dynasty/culture.md +135 -0
- package/templates/knowledge-base/references/tang-dynasty/daily-life.md +139 -0
- package/templates/knowledge-base/references/tang-dynasty/overview.md +76 -0
- package/templates/knowledge-base/references/tang-dynasty/politics.md +121 -0
- package/templates/knowledge-base/references/tang-dynasty/society.md +126 -0
- package/templates/knowledge-base/requirements/README.md +240 -0
- package/templates/knowledge-base/requirements/anti-ai-v3.md +46 -0
- package/templates/knowledge-base/requirements/anti-ai-v4.md +430 -0
- package/templates/knowledge-base/requirements/fast-paced.md +552 -0
- package/templates/knowledge-base/requirements/no-poison.md +60 -0
- package/templates/knowledge-base/requirements/romance-angst.md +102 -0
- package/templates/knowledge-base/requirements/romance-sweet.md +63 -0
- package/templates/knowledge-base/requirements/serious-literature.md +45 -0
- package/templates/knowledge-base/requirements/strong-emotion.md +60 -0
- package/templates/knowledge-base/styles/README.md +302 -0
- package/templates/knowledge-base/styles/ancient-style.md +579 -0
- package/templates/knowledge-base/styles/literary.md +439 -0
- package/templates/knowledge-base/styles/minimal.md +472 -0
- package/templates/knowledge-base/styles/natural-voice.md +930 -0
- package/templates/knowledge-base/styles/web-novel.md +525 -0
- package/templates/memory/constitution.md +140 -0
- package/templates/memory/personal-voice.md +113 -0
- package/templates/scripts/README.md +187 -0
- package/templates/scripts/bash/analyze-story.sh +170 -0
- package/templates/scripts/bash/check-consistency.sh +463 -0
- package/templates/scripts/bash/check-plot.sh +374 -0
- package/templates/scripts/bash/check-timeline.sh +346 -0
- package/templates/scripts/bash/check-world.sh +395 -0
- package/templates/scripts/bash/check-writing-state.sh +854 -0
- package/templates/scripts/bash/clarify-story.sh +117 -0
- package/templates/scripts/bash/common.sh +151 -0
- package/templates/scripts/bash/constitution.sh +114 -0
- package/templates/scripts/bash/generate-tasks.sh +65 -0
- package/templates/scripts/bash/init-tracking.sh +183 -0
- package/templates/scripts/bash/manage-relations.sh +174 -0
- package/templates/scripts/bash/plan-story.sh +100 -0
- package/templates/scripts/bash/specify-story.sh +93 -0
- package/templates/scripts/bash/tasks-story.sh +96 -0
- package/templates/scripts/bash/test-word-count.sh +182 -0
- package/templates/scripts/bash/tests/bench-preload-cache.sh +100 -0
- package/templates/scripts/bash/tests/run-all-benchmarks.sh +16 -0
- package/templates/scripts/bash/tests/test-cache-semantics.sh +199 -0
- package/templates/scripts/bash/tests/test-cross-platform.sh +35 -0
- package/templates/scripts/bash/tests/test-edge-cases-bash.sh +60 -0
- package/templates/scripts/bash/tests/test-phase1-bash.sh +28 -0
- package/templates/scripts/bash/tests/test-preload-cache.sh +123 -0
- package/templates/scripts/bash/tests/test-regex-precompile.sh +89 -0
- package/templates/scripts/bash/tests/test-regression-bash.sh +42 -0
- package/templates/scripts/bash/tests/test-task6-verification.sh +200 -0
- package/templates/scripts/bash/text-audit.sh +144 -0
- package/templates/scripts/bash/track-progress.sh +194 -0
- package/templates/scripts/powershell/analyze-story.ps1 +171 -0
- package/templates/scripts/powershell/check-analyze-stage.ps1 +110 -0
- package/templates/scripts/powershell/check-consistency.ps1 +138 -0
- package/templates/scripts/powershell/check-plot.ps1 +139 -0
- package/templates/scripts/powershell/check-timeline.ps1 +112 -0
- package/templates/scripts/powershell/check-writing-state.ps1 +490 -0
- package/templates/scripts/powershell/check-writing-state.ps1.backup +135 -0
- package/templates/scripts/powershell/clarify-story.ps1 +107 -0
- package/templates/scripts/powershell/common.ps1 +36 -0
- package/templates/scripts/powershell/constitution.ps1 +142 -0
- package/templates/scripts/powershell/generate-tasks.ps1 +75 -0
- package/templates/scripts/powershell/init-tracking.ps1 +98 -0
- package/templates/scripts/powershell/manage-relations.ps1 +134 -0
- package/templates/scripts/powershell/plan-story.ps1 +96 -0
- package/templates/scripts/powershell/specify-story.ps1 +82 -0
- package/templates/scripts/powershell/tests/bench-ps-cache.ps1 +80 -0
- package/templates/scripts/powershell/tests/test-cross-platform.ps1 +27 -0
- package/templates/scripts/powershell/tests/test-edge-cases-ps.ps1 +29 -0
- package/templates/scripts/powershell/tests/test-phase1-ps.ps1 +28 -0
- package/templates/scripts/powershell/tests/test-ps-cache.ps1 +73 -0
- package/templates/scripts/powershell/tests/test-regression-ps.ps1 +40 -0
- package/templates/scripts/powershell/text-audit.ps1 +100 -0
- package/templates/scripts/powershell/track-progress.ps1 +105 -0
- package/templates/skills/genre-knowledge/fantasy/SKILL.md +355 -0
- package/templates/skills/genre-knowledge/mystery/SKILL.md +337 -0
- package/templates/skills/genre-knowledge/romance/SKILL.md +228 -0
- package/templates/skills/genre-knowledge/sci-fi/SKILL.md +65 -0
- package/templates/skills/genre-knowledge/thriller/SKILL.md +95 -0
- package/templates/skills/quality-assurance/consistency-checker/SKILL.md +341 -0
- package/templates/skills/quality-assurance/continuity-tracker/SKILL.md +157 -0
- package/templates/skills/quality-assurance/forgotten-elements/SKILL.md +147 -0
- package/templates/skills/quality-assurance/getting-started/SKILL.md +224 -0
- package/templates/skills/quality-assurance/pacing-monitor/SKILL.md +143 -0
- package/templates/skills/quality-assurance/pov-validator/SKILL.md +135 -0
- package/templates/skills/quality-assurance/pre-write-checklist/SKILL.md +583 -0
- package/templates/skills/quality-assurance/requirement-detector/CONFLICT_RESOLUTION.md +119 -0
- package/templates/skills/quality-assurance/requirement-detector/EXAMPLES.md +146 -0
- package/templates/skills/quality-assurance/requirement-detector/KEYWORDS.md +160 -0
- package/templates/skills/quality-assurance/requirement-detector/SKILL.md +149 -0
- package/templates/skills/quality-assurance/setting-detector/SKILL.md +611 -0
- package/templates/skills/quality-assurance/style-detector/CONFLICT_RESOLUTION.md +126 -0
- package/templates/skills/quality-assurance/style-detector/EXAMPLES.md +206 -0
- package/templates/skills/quality-assurance/style-detector/KEYWORDS.md +207 -0
- package/templates/skills/quality-assurance/style-detector/SKILL.md +126 -0
- package/templates/skills/quality-assurance/workflow-guide/SKILL.md +381 -0
- package/templates/skills/writing-techniques/character-arc/SKILL.md +267 -0
- package/templates/skills/writing-techniques/dialogue-techniques/SKILL.md +366 -0
- package/templates/skills/writing-techniques/multi-thread-narrative/SKILL.md +553 -0
- package/templates/skills/writing-techniques/multi-thread-narrative/experts/thread-analyst.md +226 -0
- package/templates/skills/writing-techniques/pacing-control/SKILL.md +377 -0
- package/templates/skills/writing-techniques/reader-expectation/SKILL.md +578 -0
- package/templates/skills/writing-techniques/reader-expectation/experts/expectation-analyst.md +209 -0
- package/templates/skills/writing-techniques/revision-polish/SKILL.md +496 -0
- package/templates/skills/writing-techniques/revision-polish/experts/revision-editor.md +221 -0
- package/templates/skills/writing-techniques/scene-structure/SKILL.md +361 -0
- package/templates/skills/writing-techniques/style-learning/SKILL.md +436 -0
- package/templates/specification-example.md +146 -0
- package/templates/tracking/character-state.json +78 -0
- package/templates/tracking/plot-tracker.json +62 -0
- package/templates/tracking/relationships.json +70 -0
- package/templates/tracking/timeline.json +49 -0
- package/templates/tracking/tracking-log.md +110 -0
- package/templates/tracking/validation-rules.json +128 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 性能对比测试:预加载缓存 vs 重复 stat 调用
|
|
4
|
+
|
|
5
|
+
echo "=== 性能对比测试 ==="
|
|
6
|
+
echo ""
|
|
7
|
+
|
|
8
|
+
# 测试文件列表
|
|
9
|
+
files=(
|
|
10
|
+
"templates/config/keyword-mappings.json"
|
|
11
|
+
"templates/scripts/bash/check-writing-state.sh"
|
|
12
|
+
"templates/scripts/bash/common.sh"
|
|
13
|
+
"templates/knowledge-base/craft/dialogue.md"
|
|
14
|
+
"templates/knowledge-base/craft/scene-structure.md"
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
echo "测试文件数: ${#files[@]}"
|
|
18
|
+
echo ""
|
|
19
|
+
|
|
20
|
+
# 检测操作系统
|
|
21
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
22
|
+
STAT_CMD='stat -f "%m"'
|
|
23
|
+
echo "系统: macOS"
|
|
24
|
+
else
|
|
25
|
+
STAT_CMD='stat -c "%Y"'
|
|
26
|
+
echo "系统: Linux/WSL"
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
echo ""
|
|
30
|
+
echo "=== 方法 1: 重复 stat 调用 (100次迭代) ==="
|
|
31
|
+
time {
|
|
32
|
+
for i in {1..100}; do
|
|
33
|
+
for file in "${files[@]}"; do
|
|
34
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
35
|
+
stat -f "%m" "$file" > /dev/null 2>&1
|
|
36
|
+
else
|
|
37
|
+
stat -c "%Y" "$file" > /dev/null 2>&1
|
|
38
|
+
fi
|
|
39
|
+
done
|
|
40
|
+
done
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
echo ""
|
|
44
|
+
echo "=== 方法 2: 预加载缓存 + 数组查找 (100次迭代) ==="
|
|
45
|
+
|
|
46
|
+
# 初始化缓存
|
|
47
|
+
BASH_MAJOR_VERSION="${BASH_VERSION%%.*}"
|
|
48
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
49
|
+
declare -A FILE_MTIME_CACHE
|
|
50
|
+
fi
|
|
51
|
+
|
|
52
|
+
# 预加载函数
|
|
53
|
+
preload_file_mtimes() {
|
|
54
|
+
local file_path
|
|
55
|
+
local mtime
|
|
56
|
+
|
|
57
|
+
for file_path in "$@"; do
|
|
58
|
+
[ ! -f "$file_path" ] && continue
|
|
59
|
+
|
|
60
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
61
|
+
mtime=$(stat -f "%m" "$file_path" 2>/dev/null || echo "0")
|
|
62
|
+
else
|
|
63
|
+
mtime=$(stat -c "%Y" "$file_path" 2>/dev/null || echo "0")
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
67
|
+
FILE_MTIME_CACHE[$file_path]="$mtime"
|
|
68
|
+
fi
|
|
69
|
+
done
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
# 获取缓存的 mtime
|
|
73
|
+
get_file_mtime() {
|
|
74
|
+
local file_path="$1"
|
|
75
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
76
|
+
echo "${FILE_MTIME_CACHE[$file_path]:-0}"
|
|
77
|
+
fi
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
# 预加载(这部分时间包含在 time 中)
|
|
81
|
+
time {
|
|
82
|
+
preload_file_mtimes "${files[@]}"
|
|
83
|
+
|
|
84
|
+
# 100次迭代,每次读取所有文件的 mtime
|
|
85
|
+
for i in {1..100}; do
|
|
86
|
+
for file in "${files[@]}"; do
|
|
87
|
+
get_file_mtime "$file" > /dev/null
|
|
88
|
+
done
|
|
89
|
+
done
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
echo ""
|
|
93
|
+
echo "=== 总结 ==="
|
|
94
|
+
echo "- 方法 1: 每次调用 stat 系统调用"
|
|
95
|
+
echo "- 方法 2: 预加载到内存,后续从关联数组读取"
|
|
96
|
+
echo ""
|
|
97
|
+
echo "预期结果:"
|
|
98
|
+
echo "- 方法 1: 每次迭代都有磁盘 I/O"
|
|
99
|
+
echo "- 方法 2: 只有首次预加载有 I/O,后续都是内存操作"
|
|
100
|
+
echo "- 性能提升: 10-50x (取决于文件数量和磁盘速度)"
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
# 测试缓存语义修复
|
|
5
|
+
# 验证 mtime=-1 表示文件不存在,mtime=0 表示 stat 失败
|
|
6
|
+
|
|
7
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
8
|
+
|
|
9
|
+
echo "=== 测试缓存语义修复 ==="
|
|
10
|
+
echo ""
|
|
11
|
+
|
|
12
|
+
# 测试准备:创建临时测试文件
|
|
13
|
+
TEST_EXISTING="$SCRIPT_DIR/temp-test-existing.txt"
|
|
14
|
+
TEST_MISSING="$SCRIPT_DIR/temp-test-missing.txt"
|
|
15
|
+
|
|
16
|
+
echo "test content" > "$TEST_EXISTING"
|
|
17
|
+
|
|
18
|
+
# 清理函数
|
|
19
|
+
cleanup() {
|
|
20
|
+
rm -f "$TEST_EXISTING"
|
|
21
|
+
}
|
|
22
|
+
trap cleanup EXIT
|
|
23
|
+
|
|
24
|
+
# ============================================
|
|
25
|
+
# 复制缓存函数(从源脚本)
|
|
26
|
+
# ============================================
|
|
27
|
+
|
|
28
|
+
# Bash 版本检测
|
|
29
|
+
BASH_MAJOR_VERSION="${BASH_VERSION%%.*}"
|
|
30
|
+
|
|
31
|
+
# 缓存存储(关联数组或线性数组)
|
|
32
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
33
|
+
# Bash 4.0+: 使用关联数组
|
|
34
|
+
declare -A FILE_MTIME_CACHE
|
|
35
|
+
else
|
|
36
|
+
# Bash 3.x: 使用线性数组模拟
|
|
37
|
+
FILE_MTIME_CACHE_KEYS=()
|
|
38
|
+
FILE_MTIME_CACHE_VALUES=()
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
# 预加载文件修改时间到缓存
|
|
42
|
+
preload_file_mtimes() {
|
|
43
|
+
local file_path
|
|
44
|
+
local mtime
|
|
45
|
+
|
|
46
|
+
for file_path in "$@"; do
|
|
47
|
+
# 文件不存在:记录为 -1
|
|
48
|
+
if [ ! -f "$file_path" ]; then
|
|
49
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
50
|
+
FILE_MTIME_CACHE[$file_path]="-1"
|
|
51
|
+
else
|
|
52
|
+
FILE_MTIME_CACHE_KEYS+=("$file_path")
|
|
53
|
+
FILE_MTIME_CACHE_VALUES+=("-1")
|
|
54
|
+
fi
|
|
55
|
+
continue
|
|
56
|
+
fi
|
|
57
|
+
|
|
58
|
+
# 读取文件时间戳 (macOS/Linux 兼容)
|
|
59
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
60
|
+
mtime=$(stat -f "%m" "$file_path" 2>/dev/null || echo "0")
|
|
61
|
+
else
|
|
62
|
+
mtime=$(stat -c "%Y" "$file_path" 2>/dev/null || echo "0")
|
|
63
|
+
fi
|
|
64
|
+
|
|
65
|
+
# 存入缓存
|
|
66
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
67
|
+
FILE_MTIME_CACHE[$file_path]="$mtime"
|
|
68
|
+
else
|
|
69
|
+
FILE_MTIME_CACHE_KEYS+=("$file_path")
|
|
70
|
+
FILE_MTIME_CACHE_VALUES+=("$mtime")
|
|
71
|
+
fi
|
|
72
|
+
done
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
# 获取文件修改时间(从缓存)
|
|
76
|
+
get_file_mtime() {
|
|
77
|
+
local file_path="$1"
|
|
78
|
+
|
|
79
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
80
|
+
# Bash 4.0+: 关联数组查找
|
|
81
|
+
echo "${FILE_MTIME_CACHE[$file_path]:-0}"
|
|
82
|
+
else
|
|
83
|
+
# Bash 3.x: 线性数组查找
|
|
84
|
+
for i in "${!FILE_MTIME_CACHE_KEYS[@]}"; do
|
|
85
|
+
if [[ "${FILE_MTIME_CACHE_KEYS[$i]}" == "$file_path" ]]; then
|
|
86
|
+
echo "${FILE_MTIME_CACHE_VALUES[$i]}"
|
|
87
|
+
return 0
|
|
88
|
+
fi
|
|
89
|
+
done
|
|
90
|
+
echo "0"
|
|
91
|
+
fi
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
# 检查文件是否存在(基于缓存)
|
|
95
|
+
is_file_exists_cached() {
|
|
96
|
+
local file_path="$1"
|
|
97
|
+
local mtime=$(get_file_mtime "$file_path")
|
|
98
|
+
|
|
99
|
+
# mtime > 0: 文件存在
|
|
100
|
+
# mtime = 0: stat 失败或未缓存
|
|
101
|
+
# mtime = -1: 文件不存在
|
|
102
|
+
[[ "$mtime" != "0" && "$mtime" != "-1" ]]
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# ============================================
|
|
106
|
+
# 测试用例
|
|
107
|
+
# ============================================
|
|
108
|
+
|
|
109
|
+
# 测试 1: 存在的文件
|
|
110
|
+
echo "测试 1: 存在的文件"
|
|
111
|
+
preload_file_mtimes "$TEST_EXISTING"
|
|
112
|
+
if is_file_exists_cached "$TEST_EXISTING"; then
|
|
113
|
+
echo "✅ 存在的文件检测正确"
|
|
114
|
+
else
|
|
115
|
+
echo "❌ 存在的文件检测错误"
|
|
116
|
+
exit 1
|
|
117
|
+
fi
|
|
118
|
+
|
|
119
|
+
# 测试 2: 不存在的文件
|
|
120
|
+
echo ""
|
|
121
|
+
echo "测试 2: 不存在的文件"
|
|
122
|
+
preload_file_mtimes "$TEST_MISSING"
|
|
123
|
+
if is_file_exists_cached "$TEST_MISSING"; then
|
|
124
|
+
echo "❌ 不存在的文件被误判为存在"
|
|
125
|
+
exit 1
|
|
126
|
+
else
|
|
127
|
+
echo "✅ 不存在的文件检测正确"
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
# 测试 3: 检查缓存值
|
|
131
|
+
echo ""
|
|
132
|
+
echo "测试 3: 检查缓存值"
|
|
133
|
+
mtime_existing=$(get_file_mtime "$TEST_EXISTING")
|
|
134
|
+
mtime_missing=$(get_file_mtime "$TEST_MISSING")
|
|
135
|
+
|
|
136
|
+
echo "存在文件的 mtime: $mtime_existing (应该 > 0)"
|
|
137
|
+
echo "不存在文件的 mtime: $mtime_missing (应该 = -1)"
|
|
138
|
+
|
|
139
|
+
if [[ "$mtime_existing" -gt 0 && "$mtime_missing" == "-1" ]]; then
|
|
140
|
+
echo "✅ 缓存值语义正确"
|
|
141
|
+
else
|
|
142
|
+
echo "❌ 缓存值语义错误"
|
|
143
|
+
echo " 存在文件 mtime: $mtime_existing (期望 > 0)"
|
|
144
|
+
echo " 不存在文件 mtime: $mtime_missing (期望 = -1)"
|
|
145
|
+
exit 1
|
|
146
|
+
fi
|
|
147
|
+
|
|
148
|
+
# 测试 4: 测试批量预加载
|
|
149
|
+
echo ""
|
|
150
|
+
echo "测试 4: 批量预加载混合文件"
|
|
151
|
+
TEST_MISSING_2="$SCRIPT_DIR/temp-test-missing-2.txt"
|
|
152
|
+
preload_file_mtimes "$TEST_EXISTING" "$TEST_MISSING" "$TEST_MISSING_2"
|
|
153
|
+
|
|
154
|
+
existing_count=0
|
|
155
|
+
missing_count=0
|
|
156
|
+
|
|
157
|
+
for file in "$TEST_EXISTING" "$TEST_MISSING" "$TEST_MISSING_2"; do
|
|
158
|
+
if is_file_exists_cached "$file"; then
|
|
159
|
+
existing_count=$((existing_count + 1))
|
|
160
|
+
else
|
|
161
|
+
missing_count=$((missing_count + 1))
|
|
162
|
+
fi
|
|
163
|
+
done
|
|
164
|
+
|
|
165
|
+
echo "检测到存在的文件: $existing_count (期望 1)"
|
|
166
|
+
echo "检测到不存在的文件: $missing_count (期望 2)"
|
|
167
|
+
|
|
168
|
+
if [[ "$existing_count" -eq 1 && "$missing_count" -eq 2 ]]; then
|
|
169
|
+
echo "✅ 批量预加载检测正确"
|
|
170
|
+
else
|
|
171
|
+
echo "❌ 批量预加载检测错误"
|
|
172
|
+
exit 1
|
|
173
|
+
fi
|
|
174
|
+
|
|
175
|
+
# 测试 5: 未缓存文件(返回 mtime=0)
|
|
176
|
+
echo ""
|
|
177
|
+
echo "测试 5: 未缓存的文件"
|
|
178
|
+
UNCACHED_FILE="$SCRIPT_DIR/temp-uncached.txt"
|
|
179
|
+
mtime_uncached=$(get_file_mtime "$UNCACHED_FILE")
|
|
180
|
+
echo "未缓存文件的 mtime: $mtime_uncached (应该 = 0)"
|
|
181
|
+
|
|
182
|
+
if [[ "$mtime_uncached" == "0" ]]; then
|
|
183
|
+
echo "✅ 未缓存文件返回值正确"
|
|
184
|
+
else
|
|
185
|
+
echo "❌ 未缓存文件返回值错误 (期望 0,实际 $mtime_uncached)"
|
|
186
|
+
exit 1
|
|
187
|
+
fi
|
|
188
|
+
|
|
189
|
+
if is_file_exists_cached "$UNCACHED_FILE"; then
|
|
190
|
+
echo "❌ 未缓存文件被误判为存在"
|
|
191
|
+
exit 1
|
|
192
|
+
else
|
|
193
|
+
echo "✅ 未缓存文件检测正确(不存在)"
|
|
194
|
+
fi
|
|
195
|
+
|
|
196
|
+
echo ""
|
|
197
|
+
echo "=== 测试完成 ==="
|
|
198
|
+
echo ""
|
|
199
|
+
echo "所有测试通过!缓存语义修复成功。"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
echo "=== Phase 1 跨平台兼容性测试 ==="
|
|
6
|
+
echo ""
|
|
7
|
+
|
|
8
|
+
echo "【系统信息】"
|
|
9
|
+
echo "操作系统: $(uname -s)"
|
|
10
|
+
echo "Bash 版本: $BASH_VERSION"
|
|
11
|
+
echo ""
|
|
12
|
+
|
|
13
|
+
echo "【Bash 数组类型检测】"
|
|
14
|
+
bash_major_version="${BASH_VERSION%%.*}"
|
|
15
|
+
if [[ "$bash_major_version" -ge 4 ]]; then
|
|
16
|
+
echo "✅ Bash 4.0+ 检测到 - 应使用关联数组"
|
|
17
|
+
array_type="associative"
|
|
18
|
+
else
|
|
19
|
+
echo "✅ Bash 3.x 检测到 - 应使用线性数组(兼容模式)"
|
|
20
|
+
array_type="linear"
|
|
21
|
+
fi
|
|
22
|
+
|
|
23
|
+
echo ""
|
|
24
|
+
echo "【路径处理测试】"
|
|
25
|
+
# 测试路径分隔符处理
|
|
26
|
+
test_path="templates/config/keyword-mappings.json"
|
|
27
|
+
if [[ -f "$test_path" ]]; then
|
|
28
|
+
echo "✅ 路径处理正常: $test_path"
|
|
29
|
+
else
|
|
30
|
+
echo "❌ 路径处理失败: $test_path"
|
|
31
|
+
exit 1
|
|
32
|
+
fi
|
|
33
|
+
|
|
34
|
+
echo ""
|
|
35
|
+
echo "✅ 跨平台兼容性测试通过(数组类型: $array_type)"
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
echo "=== Phase 1 边界情况测试 (Bash) ==="
|
|
6
|
+
echo ""
|
|
7
|
+
|
|
8
|
+
# 加载缓存函数(假设在 common.sh 中)
|
|
9
|
+
# 这里模拟测试
|
|
10
|
+
|
|
11
|
+
echo "测试 5.1: 文件不存在处理"
|
|
12
|
+
|
|
13
|
+
# 创建临时测试脚本
|
|
14
|
+
cat > /tmp/test-nonexistent.sh <<'EOF'
|
|
15
|
+
#!/bin/bash
|
|
16
|
+
|
|
17
|
+
# 模拟 preload_file_mtimes 函数
|
|
18
|
+
preload_file_mtimes() {
|
|
19
|
+
local file_path="$1"
|
|
20
|
+
|
|
21
|
+
if [[ ! -f "$file_path" ]]; then
|
|
22
|
+
echo "文件不存在: $file_path" >&2
|
|
23
|
+
return 1
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
return 0
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# 模拟 get_file_mtime 函数
|
|
30
|
+
get_file_mtime() {
|
|
31
|
+
local file_path="$1"
|
|
32
|
+
|
|
33
|
+
if [[ ! -f "$file_path" ]]; then
|
|
34
|
+
echo "-1" # 哨兵值
|
|
35
|
+
return
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
# 返回实际时间戳
|
|
39
|
+
if stat -c %Y "$file_path" &>/dev/null; then
|
|
40
|
+
stat -c %Y "$file_path"
|
|
41
|
+
else
|
|
42
|
+
stat -f %m "$file_path"
|
|
43
|
+
fi
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# 测试不存在的文件
|
|
47
|
+
mtime=$(get_file_mtime "templates/nonexistent-file.md")
|
|
48
|
+
if [[ "$mtime" == "-1" ]]; then
|
|
49
|
+
echo "✅ 正确处理文件不存在(mtime = -1)"
|
|
50
|
+
else
|
|
51
|
+
echo "❌ 文件不存在处理错误:mtime = $mtime"
|
|
52
|
+
exit 1
|
|
53
|
+
fi
|
|
54
|
+
EOF
|
|
55
|
+
|
|
56
|
+
bash /tmp/test-nonexistent.sh
|
|
57
|
+
rm /tmp/test-nonexistent.sh
|
|
58
|
+
|
|
59
|
+
echo ""
|
|
60
|
+
echo "✅ Bash 边界情况测试通过"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
|
|
4
|
+
echo "=== Phase 1 Bash 缓存测试 ==="
|
|
5
|
+
echo ""
|
|
6
|
+
|
|
7
|
+
# 测试 2.1: 功能测试
|
|
8
|
+
echo "测试 2.1: 运行功能测试"
|
|
9
|
+
bash test-preload-cache.sh
|
|
10
|
+
echo ""
|
|
11
|
+
|
|
12
|
+
# 测试 2.2: 性能测试
|
|
13
|
+
echo "测试 2.2: 运行性能测试"
|
|
14
|
+
bash bench-preload-cache.sh
|
|
15
|
+
echo ""
|
|
16
|
+
|
|
17
|
+
# 测试 2.3: Bash 版本检测
|
|
18
|
+
echo "测试 2.3: Bash 版本检测"
|
|
19
|
+
bash_version="${BASH_VERSION%%.*}"
|
|
20
|
+
echo "当前 Bash 版本: $BASH_VERSION"
|
|
21
|
+
if [[ "$bash_version" -ge 4 ]]; then
|
|
22
|
+
echo "✅ 使用关联数组(Bash 4.0+)"
|
|
23
|
+
else
|
|
24
|
+
echo "✅ 使用线性数组(Bash 3.x 兼容)"
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
echo ""
|
|
28
|
+
echo "✅ Bash 缓存测试全部通过"
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# 测试预加载缓存功能
|
|
4
|
+
|
|
5
|
+
echo "=== 测试预加载缓存 ==="
|
|
6
|
+
echo ""
|
|
7
|
+
|
|
8
|
+
# Bash 版本检测
|
|
9
|
+
BASH_MAJOR_VERSION="${BASH_VERSION%%.*}"
|
|
10
|
+
echo "Bash 主版本: $BASH_MAJOR_VERSION"
|
|
11
|
+
|
|
12
|
+
# 缓存存储
|
|
13
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
14
|
+
declare -A FILE_MTIME_CACHE
|
|
15
|
+
echo "使用关联数组"
|
|
16
|
+
else
|
|
17
|
+
FILE_MTIME_CACHE_KEYS=()
|
|
18
|
+
FILE_MTIME_CACHE_VALUES=()
|
|
19
|
+
echo "使用线性数组"
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
# 预加载函数
|
|
23
|
+
preload_file_mtimes() {
|
|
24
|
+
local file_path
|
|
25
|
+
local mtime
|
|
26
|
+
|
|
27
|
+
for file_path in "$@"; do
|
|
28
|
+
[ ! -f "$file_path" ] && continue
|
|
29
|
+
|
|
30
|
+
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
31
|
+
mtime=$(stat -f "%m" "$file_path" 2>/dev/null || echo "0")
|
|
32
|
+
else
|
|
33
|
+
mtime=$(stat -c "%Y" "$file_path" 2>/dev/null || echo "0")
|
|
34
|
+
fi
|
|
35
|
+
|
|
36
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
37
|
+
FILE_MTIME_CACHE[$file_path]="$mtime"
|
|
38
|
+
else
|
|
39
|
+
FILE_MTIME_CACHE_KEYS+=("$file_path")
|
|
40
|
+
FILE_MTIME_CACHE_VALUES+=("$mtime")
|
|
41
|
+
fi
|
|
42
|
+
done
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# 获取缓存的 mtime
|
|
46
|
+
get_file_mtime() {
|
|
47
|
+
local file_path="$1"
|
|
48
|
+
|
|
49
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
50
|
+
echo "${FILE_MTIME_CACHE[$file_path]:-0}"
|
|
51
|
+
else
|
|
52
|
+
for i in "${!FILE_MTIME_CACHE_KEYS[@]}"; do
|
|
53
|
+
if [[ "${FILE_MTIME_CACHE_KEYS[$i]}" == "$file_path" ]]; then
|
|
54
|
+
echo "${FILE_MTIME_CACHE_VALUES[$i]}"
|
|
55
|
+
return 0
|
|
56
|
+
fi
|
|
57
|
+
done
|
|
58
|
+
echo "0"
|
|
59
|
+
fi
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
# 检查是否已缓存
|
|
63
|
+
is_file_cached() {
|
|
64
|
+
local file_path="$1"
|
|
65
|
+
|
|
66
|
+
if [[ "$BASH_MAJOR_VERSION" -ge 4 ]]; then
|
|
67
|
+
[[ ${FILE_MTIME_CACHE[$file_path]+isset} ]]
|
|
68
|
+
else
|
|
69
|
+
for key in "${FILE_MTIME_CACHE_KEYS[@]}"; do
|
|
70
|
+
[[ "$key" == "$file_path" ]] && return 0
|
|
71
|
+
done
|
|
72
|
+
return 1
|
|
73
|
+
fi
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
echo ""
|
|
77
|
+
echo "=== 测试 1: 预加载文件 ==="
|
|
78
|
+
files=(
|
|
79
|
+
"templates/config/keyword-mappings.json"
|
|
80
|
+
"templates/scripts/bash/check-writing-state.sh"
|
|
81
|
+
"templates/scripts/bash/common.sh"
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
echo "预加载 ${#files[@]} 个文件..."
|
|
85
|
+
preload_file_mtimes "${files[@]}"
|
|
86
|
+
|
|
87
|
+
echo "缓存大小: ${#FILE_MTIME_CACHE[@]}"
|
|
88
|
+
|
|
89
|
+
echo ""
|
|
90
|
+
echo "=== 测试 2: 检查缓存状态 ==="
|
|
91
|
+
for file in "${files[@]}"; do
|
|
92
|
+
if is_file_cached "$file"; then
|
|
93
|
+
mtime=$(get_file_mtime "$file")
|
|
94
|
+
echo "✅ $file (mtime: $mtime)"
|
|
95
|
+
else
|
|
96
|
+
echo "❌ $file 未缓存"
|
|
97
|
+
fi
|
|
98
|
+
done
|
|
99
|
+
|
|
100
|
+
echo ""
|
|
101
|
+
echo "=== 测试 3: 获取 mtime (不使用命令替换) ==="
|
|
102
|
+
for file in "${files[@]}"; do
|
|
103
|
+
get_file_mtime "$file"
|
|
104
|
+
done
|
|
105
|
+
|
|
106
|
+
echo ""
|
|
107
|
+
echo "=== 测试 4: 测试不存在的文件 ==="
|
|
108
|
+
nonexistent="/nonexistent/file.txt"
|
|
109
|
+
if is_file_cached "$nonexistent"; then
|
|
110
|
+
echo "❌ 不存在的文件被标记为已缓存"
|
|
111
|
+
else
|
|
112
|
+
echo "✅ 不存在的文件未被缓存"
|
|
113
|
+
fi
|
|
114
|
+
|
|
115
|
+
mtime=$(get_file_mtime "$nonexistent")
|
|
116
|
+
if [[ "$mtime" == "0" ]]; then
|
|
117
|
+
echo "✅ 未缓存文件返回 0"
|
|
118
|
+
else
|
|
119
|
+
echo "❌ 未缓存文件返回: $mtime"
|
|
120
|
+
fi
|
|
121
|
+
|
|
122
|
+
echo ""
|
|
123
|
+
echo "=== 测试完成 ==="
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
echo "=== Phase 1 预编译正则表达式测试 ==="
|
|
6
|
+
echo ""
|
|
7
|
+
|
|
8
|
+
# 测试 1.1: 验证 JSON 结构
|
|
9
|
+
echo "测试 1.1: 验证 JSON 结构"
|
|
10
|
+
version=$(jq -r '.version' templates/config/keyword-mappings.json)
|
|
11
|
+
if [[ "$version" == "1.1.0" ]]; then
|
|
12
|
+
echo "✅ 版本号正确: $version"
|
|
13
|
+
else
|
|
14
|
+
echo "❌ 版本号错误: $version (期望 1.1.0)"
|
|
15
|
+
exit 1
|
|
16
|
+
fi
|
|
17
|
+
|
|
18
|
+
# 测试 1.2: 验证正则字段
|
|
19
|
+
echo ""
|
|
20
|
+
echo "测试 1.2: 验证正则字段"
|
|
21
|
+
mappings=(
|
|
22
|
+
"craft-knowledge.dialogue"
|
|
23
|
+
"craft-knowledge.character-arc"
|
|
24
|
+
"craft-knowledge.pacing"
|
|
25
|
+
"craft-knowledge.show-not-tell"
|
|
26
|
+
"craft-knowledge.scene-structure"
|
|
27
|
+
"genre-knowledge.romance"
|
|
28
|
+
"genre-knowledge.mystery"
|
|
29
|
+
"quality-assurance.consistency"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
all_passed=true
|
|
33
|
+
for mapping in "${mappings[@]}"; do
|
|
34
|
+
# 使用 jq 的嵌套路径语法
|
|
35
|
+
category=$(echo "$mapping" | cut -d. -f1)
|
|
36
|
+
name=$(echo "$mapping" | cut -d. -f2)
|
|
37
|
+
|
|
38
|
+
regex=$(jq -r ".mappings[\"$category\"][\"$name\"].regex" templates/config/keyword-mappings.json)
|
|
39
|
+
regex_flags=$(jq -r ".mappings[\"$category\"][\"$name\"].regex_flags" templates/config/keyword-mappings.json)
|
|
40
|
+
|
|
41
|
+
if [[ -n "$regex" && "$regex" != "null" ]]; then
|
|
42
|
+
echo "✅ $mapping: regex='$regex', flags='$regex_flags'"
|
|
43
|
+
else
|
|
44
|
+
echo "❌ $mapping: 缺少 regex 字段"
|
|
45
|
+
all_passed=false
|
|
46
|
+
fi
|
|
47
|
+
done
|
|
48
|
+
|
|
49
|
+
if [[ "$all_passed" != true ]]; then
|
|
50
|
+
exit 1
|
|
51
|
+
fi
|
|
52
|
+
|
|
53
|
+
# 测试 1.3: 测试正则匹配
|
|
54
|
+
echo ""
|
|
55
|
+
echo "测试 1.3: 测试正则匹配"
|
|
56
|
+
declare -A test_cases=(
|
|
57
|
+
["dialogue:对话"]="craft-knowledge.dialogue"
|
|
58
|
+
["dialogue:conversation"]="craft-knowledge.dialogue"
|
|
59
|
+
["dialogue:DIALOGUE"]="craft-knowledge.dialogue" # 大小写不敏感
|
|
60
|
+
["pacing:节奏"]="craft-knowledge.pacing"
|
|
61
|
+
["pacing:太快"]="craft-knowledge.pacing"
|
|
62
|
+
["character-arc:character arc"]="craft-knowledge.character-arc" # 支持空格
|
|
63
|
+
["consistency:一致性"]="quality-assurance.consistency"
|
|
64
|
+
["romance:爱情"]="genre-knowledge.romance"
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
for test_case in "${!test_cases[@]}"; do
|
|
68
|
+
keyword=$(echo "$test_case" | cut -d: -f2)
|
|
69
|
+
mapping=${test_cases[$test_case]}
|
|
70
|
+
|
|
71
|
+
category=$(echo "$mapping" | cut -d. -f1)
|
|
72
|
+
name=$(echo "$mapping" | cut -d. -f2)
|
|
73
|
+
|
|
74
|
+
regex=$(jq -r ".mappings[\"$category\"][\"$name\"].regex" templates/config/keyword-mappings.json)
|
|
75
|
+
|
|
76
|
+
if echo "$keyword" | grep -iE "$regex" > /dev/null; then
|
|
77
|
+
echo "✅ $mapping + '$keyword' → 匹配成功"
|
|
78
|
+
else
|
|
79
|
+
echo "❌ $mapping + '$keyword' → 匹配失败"
|
|
80
|
+
all_passed=false
|
|
81
|
+
fi
|
|
82
|
+
done
|
|
83
|
+
|
|
84
|
+
if [[ "$all_passed" != true ]]; then
|
|
85
|
+
exit 1
|
|
86
|
+
fi
|
|
87
|
+
|
|
88
|
+
echo ""
|
|
89
|
+
echo "✅ 所有预编译正则测试通过 (3/3)"
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
echo "=== Phase 1 回归测试 (Bash) ==="
|
|
6
|
+
echo ""
|
|
7
|
+
|
|
8
|
+
echo "测试 7.1: 脚本正常运行"
|
|
9
|
+
if bash templates/scripts/bash/check-writing-state.sh --help > /dev/null 2>&1; then
|
|
10
|
+
echo "✅ 脚本帮助信息正常"
|
|
11
|
+
else
|
|
12
|
+
echo "⚠️ 脚本无 --help 选项(可能是正常的)"
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
echo ""
|
|
16
|
+
echo "测试 7.2: JSON 输出格式"
|
|
17
|
+
output=$(bash templates/scripts/bash/check-writing-state.sh 2>/dev/null || echo "{}")
|
|
18
|
+
|
|
19
|
+
if echo "$output" | jq empty 2>/dev/null; then
|
|
20
|
+
echo "✅ JSON 格式正确"
|
|
21
|
+
else
|
|
22
|
+
echo "❌ JSON 格式错误"
|
|
23
|
+
echo "输出内容:"
|
|
24
|
+
echo "$output"
|
|
25
|
+
exit 1
|
|
26
|
+
fi
|
|
27
|
+
|
|
28
|
+
echo ""
|
|
29
|
+
echo "测试 7.3: 必需字段存在性"
|
|
30
|
+
required_fields=("status")
|
|
31
|
+
all_exist=true
|
|
32
|
+
|
|
33
|
+
for field in "${required_fields[@]}"; do
|
|
34
|
+
if echo "$output" | jq -e ".$field" > /dev/null 2>&1; then
|
|
35
|
+
echo "✅ 字段存在: $field"
|
|
36
|
+
else
|
|
37
|
+
echo "⚠️ 字段不存在: $field(可能是预期的)"
|
|
38
|
+
fi
|
|
39
|
+
done
|
|
40
|
+
|
|
41
|
+
echo ""
|
|
42
|
+
echo "✅ Bash 回归测试通过"
|