novelws 4.0.0 → 5.0.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 +100 -623
- package/README.md +79 -594
- package/dist/cli.js +1 -3
- package/dist/cli.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +12 -99
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/upgrade.d.ts.map +1 -1
- package/dist/commands/upgrade.js +17 -108
- package/dist/commands/upgrade.js.map +1 -1
- package/dist/core/config.d.ts +1 -37
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +6 -45
- package/dist/core/config.js.map +1 -1
- package/dist/core/errors.d.ts +0 -31
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/errors.js +0 -58
- package/dist/core/errors.js.map +1 -1
- package/dist/utils/diagnostics.d.ts +2 -16
- package/dist/utils/diagnostics.d.ts.map +1 -1
- package/dist/utils/diagnostics.js +5 -72
- package/dist/utils/diagnostics.js.map +1 -1
- package/dist/utils/project.d.ts +1 -1
- package/dist/utils/project.d.ts.map +1 -1
- package/dist/utils/project.js +3 -3
- package/dist/utils/project.js.map +1 -1
- package/package.json +1 -2
- package/templates/commands/analyze.md +65 -265
- package/templates/commands/expand.md +70 -0
- package/templates/commands/plan.md +47 -452
- package/templates/commands/specify.md +43 -869
- package/templates/commands/write.md +49 -643
- package/templates/dot-claude/CLAUDE.md +38 -202
- package/templates/resources/anti-ai.md +16 -0
- package/templates/resources/style-reference.md +19 -0
- package/templates/tracking/character-state.json +1 -76
- package/templates/tracking/plot-tracker.json +3 -60
- package/templates/tracking/relationships.json +1 -68
- package/templates/tracking/timeline.json +1 -47
- package/dist/commands/plugin.d.ts +0 -6
- package/dist/commands/plugin.d.ts.map +0 -1
- package/dist/commands/plugin.js +0 -135
- package/dist/commands/plugin.js.map +0 -1
- package/dist/plugins/identifier.d.ts +0 -13
- package/dist/plugins/identifier.d.ts.map +0 -1
- package/dist/plugins/identifier.js +0 -72
- package/dist/plugins/identifier.js.map +0 -1
- package/dist/plugins/installers/base.d.ts +0 -27
- package/dist/plugins/installers/base.d.ts.map +0 -1
- package/dist/plugins/installers/base.js +0 -30
- package/dist/plugins/installers/base.js.map +0 -1
- package/dist/plugins/installers/github.d.ts +0 -22
- package/dist/plugins/installers/github.d.ts.map +0 -1
- package/dist/plugins/installers/github.js +0 -133
- package/dist/plugins/installers/github.js.map +0 -1
- package/dist/plugins/installers/local.d.ts +0 -16
- package/dist/plugins/installers/local.d.ts.map +0 -1
- package/dist/plugins/installers/local.js +0 -69
- package/dist/plugins/installers/local.js.map +0 -1
- package/dist/plugins/installers/npm.d.ts +0 -20
- package/dist/plugins/installers/npm.d.ts.map +0 -1
- package/dist/plugins/installers/npm.js +0 -99
- package/dist/plugins/installers/npm.js.map +0 -1
- package/dist/plugins/manager.d.ts +0 -77
- package/dist/plugins/manager.d.ts.map +0 -1
- package/dist/plugins/manager.js +0 -349
- package/dist/plugins/manager.js.map +0 -1
- package/dist/plugins/registry.d.ts +0 -48
- package/dist/plugins/registry.d.ts.map +0 -1
- package/dist/plugins/registry.js +0 -111
- package/dist/plugins/registry.js.map +0 -1
- package/dist/plugins/types.d.ts +0 -66
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/plugins/types.js +0 -2
- package/dist/plugins/types.js.map +0 -1
- package/dist/plugins/validator.d.ts +0 -19
- package/dist/plugins/validator.d.ts.map +0 -1
- package/dist/plugins/validator.js +0 -164
- package/dist/plugins/validator.js.map +0 -1
- package/dist/utils/logger.d.ts +0 -13
- package/dist/utils/logger.d.ts.map +0 -1
- package/dist/utils/logger.js +0 -48
- package/dist/utils/logger.js.map +0 -1
- package/plugins/authentic-voice/README.md +0 -31
- package/plugins/authentic-voice/commands/authentic-voice.md +0 -73
- package/plugins/authentic-voice/commands/authenticity-audit.md +0 -37
- package/plugins/authentic-voice/config.yaml +0 -30
- package/plugins/authentic-voice/experts/authentic-editor.md +0 -27
- package/plugins/export/README.md +0 -319
- package/plugins/export/commands/export.md +0 -460
- package/plugins/export/commands/generate-cover.md +0 -256
- package/plugins/export/commands/metadata.md +0 -309
- package/plugins/export/config.yaml +0 -47
- package/plugins/export/experts/publishing-expert.md +0 -171
- package/plugins/export/templates/epub/chapter-template.html +0 -13
- package/plugins/export/templates/epub/cover-template.html +0 -14
- package/plugins/export/templates/epub/stylesheet.css +0 -200
- package/plugins/export/templates/pdf/ebook-style.css +0 -137
- package/plugins/export/templates/pdf/print-style.css +0 -179
- package/plugins/export/templates/platforms/jinjiang-format.md +0 -101
- package/plugins/export/templates/platforms/qidian-format.md +0 -108
- package/plugins/export/templates/platforms/tomato-format.md +0 -95
- package/plugins/translate/README.md +0 -265
- package/plugins/translate/commands/glossary.md +0 -731
- package/plugins/translate/commands/translate-preview.md +0 -543
- package/plugins/translate/commands/translate.md +0 -649
- package/plugins/translate/config.yaml +0 -43
- package/plugins/translate/experts/literary-translator.md +0 -605
- package/templates/commands/character.md +0 -287
- package/templates/commands/checklist.md +0 -744
- package/templates/commands/clarify.md +0 -269
- package/templates/commands/constitution.md +0 -269
- package/templates/commands/expert.md +0 -188
- package/templates/commands/facts.md +0 -552
- package/templates/commands/guide.md +0 -900
- package/templates/commands/help-me.md +0 -221
- package/templates/commands/recap.md +0 -748
- package/templates/commands/relations.md +0 -385
- package/templates/commands/revise.md +0 -450
- package/templates/commands/search.md +0 -531
- package/templates/commands/tasks.md +0 -396
- package/templates/commands/timeline.md +0 -309
- package/templates/commands/track-init.md +0 -149
- package/templates/commands/track.md +0 -704
- package/templates/commands/volume-summary.md +0 -471
- package/templates/knowledge/audit-config.json +0 -26
- package/templates/knowledge/character-profiles.md +0 -152
- package/templates/knowledge/character-voices.md +0 -137
- package/templates/knowledge/locations.md +0 -184
- package/templates/knowledge/world-setting.md +0 -121
- package/templates/resources/character-archetypes/01-hero.md +0 -233
- package/templates/resources/character-archetypes/02-mentor.md +0 -177
- package/templates/resources/character-archetypes/03-shadow.md +0 -221
- package/templates/resources/character-archetypes/04-ally.md +0 -178
- package/templates/resources/character-archetypes/05-shapeshifter.md +0 -177
- package/templates/resources/character-archetypes/06-trickster.md +0 -181
- package/templates/resources/character-archetypes/07-threshold-guardian.md +0 -177
- package/templates/resources/character-archetypes/08-herald.md +0 -180
- package/templates/resources/character-archetypes/09-father.md +0 -249
- package/templates/resources/character-archetypes/10-mother.md +0 -202
- package/templates/resources/character-archetypes/11-child.md +0 -183
- package/templates/resources/character-archetypes/12-sage.md +0 -202
- package/templates/resources/character-archetypes/README.md +0 -60
- package/templates/resources/character-archetypes/application-guide.md +0 -222
- package/templates/resources/character-archetypes/archetype-combinations.md +0 -242
- package/templates/resources/character-archetypes/config.yaml +0 -28
- package/templates/resources/character-archetypes/examples-analysis.md +0 -223
- package/templates/resources/config/keyword-mappings.json +0 -226
- package/templates/resources/config/specification-example.md +0 -146
- package/templates/resources/craft/character-arc.md +0 -1153
- package/templates/resources/craft/dialogue.md +0 -1170
- package/templates/resources/craft/hook-design.md +0 -345
- package/templates/resources/craft/pacing.md +0 -1200
- package/templates/resources/craft/power-system.md +0 -254
- package/templates/resources/craft/scene-structure.md +0 -1136
- package/templates/resources/craft/show-not-tell.md +0 -1012
- package/templates/resources/craft/story-structures.md +0 -134
- package/templates/resources/craft/tension-management.md +0 -168
- package/templates/resources/emotional-beats/01-first-meeting.md +0 -145
- package/templates/resources/emotional-beats/02-bonding-moment.md +0 -226
- package/templates/resources/emotional-beats/03-declaration.md +0 -284
- package/templates/resources/emotional-beats/04-triumph.md +0 -240
- package/templates/resources/emotional-beats/05-reunion.md +0 -396
- package/templates/resources/emotional-beats/06-forgiveness.md +0 -204
- package/templates/resources/emotional-beats/07-betrayal.md +0 -204
- package/templates/resources/emotional-beats/08-loss.md +0 -214
- package/templates/resources/emotional-beats/09-rejection.md +0 -254
- package/templates/resources/emotional-beats/10-failure.md +0 -244
- package/templates/resources/emotional-beats/11-misunderstanding.md +0 -205
- package/templates/resources/emotional-beats/12-farewell.md +0 -283
- package/templates/resources/emotional-beats/13-revelation.md +0 -242
- package/templates/resources/emotional-beats/14-point-of-no-return.md +0 -215
- package/templates/resources/emotional-beats/15-dark-night.md +0 -244
- package/templates/resources/emotional-beats/16-sacrifice.md +0 -246
- package/templates/resources/emotional-beats/17-awakening.md +0 -246
- package/templates/resources/emotional-beats/18-confrontation.md +0 -217
- package/templates/resources/emotional-beats/19-bittersweet-goodbye.md +0 -368
- package/templates/resources/emotional-beats/20-moral-dilemma.md +0 -248
- package/templates/resources/emotional-beats/21-temptation.md +0 -240
- package/templates/resources/emotional-beats/22-redemption.md +0 -210
- package/templates/resources/emotional-beats/README.md +0 -104
- package/templates/resources/emotional-beats/beat-sequences.md +0 -276
- package/templates/resources/emotional-beats/config.yaml +0 -30
- package/templates/resources/emotional-beats/pacing-guide.md +0 -390
- package/templates/resources/genres/game-lit.md +0 -174
- package/templates/resources/genres/historical.md +0 -1127
- package/templates/resources/genres/horror.md +0 -211
- package/templates/resources/genres/military.md +0 -209
- package/templates/resources/genres/mystery.md +0 -1123
- package/templates/resources/genres/rebirth.md +0 -177
- package/templates/resources/genres/revenge.md +0 -846
- package/templates/resources/genres/romance.md +0 -948
- package/templates/resources/genres/sci-fi.md +0 -156
- package/templates/resources/genres/sports.md +0 -216
- package/templates/resources/genres/thriller.md +0 -166
- package/templates/resources/genres/urban.md +0 -170
- package/templates/resources/genres/workplace.md +0 -214
- package/templates/resources/genres/wuxia.md +0 -143
- package/templates/resources/genres/xuanhuan.md +0 -234
- package/templates/resources/genres/youth.md +0 -219
- package/templates/resources/memory/personal-voice.md +0 -113
- package/templates/resources/references/README.md +0 -96
- package/templates/resources/references/china-1920s/culture.md +0 -423
- package/templates/resources/references/china-1920s/daily-life.md +0 -616
- package/templates/resources/references/china-1920s/overview.md +0 -298
- package/templates/resources/references/china-1920s/society.md +0 -703
- package/templates/resources/references/china-1920s/warlords.md +0 -427
- package/templates/resources/references/cultivation-world/daily-life.md +0 -108
- package/templates/resources/references/cultivation-world/overview.md +0 -64
- package/templates/resources/references/cultivation-world/power-system.md +0 -108
- package/templates/resources/references/cultivation-world/sects.md +0 -104
- package/templates/resources/references/cultivation-world/world-setting.md +0 -108
- package/templates/resources/references/modern-workplace/corporate.md +0 -115
- package/templates/resources/references/modern-workplace/daily-life.md +0 -129
- package/templates/resources/references/modern-workplace/overview.md +0 -73
- package/templates/resources/references/modern-workplace/relationships.md +0 -107
- package/templates/resources/references/modern-workplace/tech-industry.md +0 -131
- package/templates/resources/references/tang-dynasty/culture.md +0 -135
- package/templates/resources/references/tang-dynasty/daily-life.md +0 -139
- package/templates/resources/references/tang-dynasty/overview.md +0 -76
- package/templates/resources/references/tang-dynasty/politics.md +0 -121
- package/templates/resources/references/tang-dynasty/society.md +0 -126
- package/templates/resources/requirements/README.md +0 -240
- package/templates/resources/requirements/anti-ai-v3.md +0 -46
- package/templates/resources/requirements/anti-ai-v4-deprecated.md +0 -442
- package/templates/resources/requirements/anti-ai-v5-balanced.md +0 -203
- package/templates/resources/requirements/concretization.md +0 -90
- package/templates/resources/requirements/fast-paced.md +0 -552
- package/templates/resources/requirements/no-poison.md +0 -60
- package/templates/resources/requirements/romance-angst.md +0 -102
- package/templates/resources/requirements/romance-sweet.md +0 -63
- package/templates/resources/requirements/serious-literature.md +0 -45
- package/templates/resources/requirements/strong-emotion.md +0 -60
- package/templates/resources/scripts/README.md +0 -187
- package/templates/resources/scripts/bash/analyze-story.sh +0 -170
- package/templates/resources/scripts/bash/check-analyze-stage.sh +0 -108
- package/templates/resources/scripts/bash/check-consistency.sh +0 -463
- package/templates/resources/scripts/bash/check-facts.sh +0 -214
- package/templates/resources/scripts/bash/check-plot.sh +0 -374
- package/templates/resources/scripts/bash/check-timeline.sh +0 -346
- package/templates/resources/scripts/bash/check-world.sh +0 -395
- package/templates/resources/scripts/bash/check-writing-state.sh +0 -854
- package/templates/resources/scripts/bash/clarify-story.sh +0 -117
- package/templates/resources/scripts/bash/common.sh +0 -151
- package/templates/resources/scripts/bash/constitution.sh +0 -114
- package/templates/resources/scripts/bash/generate-tasks.sh +0 -65
- package/templates/resources/scripts/bash/init-tracking.sh +0 -183
- package/templates/resources/scripts/bash/manage-relations.sh +0 -174
- package/templates/resources/scripts/bash/migrate-tracking.sh +0 -183
- package/templates/resources/scripts/bash/plan-story.sh +0 -100
- package/templates/resources/scripts/bash/specify-story.sh +0 -93
- package/templates/resources/scripts/bash/tasks-story.sh +0 -96
- package/templates/resources/scripts/bash/test-word-count.sh +0 -182
- package/templates/resources/scripts/bash/tests/bench-preload-cache.sh +0 -100
- package/templates/resources/scripts/bash/tests/run-all-benchmarks.sh +0 -16
- package/templates/resources/scripts/bash/tests/test-cache-semantics.sh +0 -199
- package/templates/resources/scripts/bash/tests/test-cross-platform.sh +0 -35
- package/templates/resources/scripts/bash/tests/test-edge-cases-bash.sh +0 -60
- package/templates/resources/scripts/bash/tests/test-phase1-bash.sh +0 -28
- package/templates/resources/scripts/bash/tests/test-preload-cache.sh +0 -123
- package/templates/resources/scripts/bash/tests/test-regex-precompile.sh +0 -89
- package/templates/resources/scripts/bash/tests/test-regression-bash.sh +0 -42
- package/templates/resources/scripts/bash/tests/test-task6-verification.sh +0 -200
- package/templates/resources/scripts/bash/text-audit.sh +0 -144
- package/templates/resources/scripts/bash/track-progress.sh +0 -194
- package/templates/resources/scripts/powershell/analyze-story.ps1 +0 -174
- package/templates/resources/scripts/powershell/check-analyze-stage.ps1 +0 -110
- package/templates/resources/scripts/powershell/check-consistency.ps1 +0 -138
- package/templates/resources/scripts/powershell/check-facts.ps1 +0 -195
- package/templates/resources/scripts/powershell/check-plot.ps1 +0 -139
- package/templates/resources/scripts/powershell/check-timeline.ps1 +0 -112
- package/templates/resources/scripts/powershell/check-writing-state.ps1 +0 -486
- package/templates/resources/scripts/powershell/clarify-story.ps1 +0 -107
- package/templates/resources/scripts/powershell/common.ps1 +0 -36
- package/templates/resources/scripts/powershell/constitution.ps1 +0 -145
- package/templates/resources/scripts/powershell/generate-tasks.ps1 +0 -70
- package/templates/resources/scripts/powershell/init-tracking.ps1 +0 -98
- package/templates/resources/scripts/powershell/manage-relations.ps1 +0 -134
- package/templates/resources/scripts/powershell/migrate-tracking.ps1 +0 -145
- package/templates/resources/scripts/powershell/plan-story.ps1 +0 -99
- package/templates/resources/scripts/powershell/specify-story.ps1 +0 -85
- package/templates/resources/scripts/powershell/tests/bench-ps-cache.ps1 +0 -80
- package/templates/resources/scripts/powershell/tests/test-cross-platform.ps1 +0 -27
- package/templates/resources/scripts/powershell/tests/test-edge-cases-ps.ps1 +0 -29
- package/templates/resources/scripts/powershell/tests/test-phase1-ps.ps1 +0 -28
- package/templates/resources/scripts/powershell/tests/test-ps-cache.ps1 +0 -73
- package/templates/resources/scripts/powershell/tests/test-regression-ps.ps1 +0 -40
- package/templates/resources/scripts/powershell/text-audit.ps1 +0 -102
- package/templates/resources/scripts/powershell/track-progress.ps1 +0 -105
- package/templates/resources/styles/README.md +0 -302
- package/templates/resources/styles/ancient-style.md +0 -579
- package/templates/resources/styles/literary.md +0 -439
- package/templates/resources/styles/minimal.md +0 -472
- package/templates/resources/styles/natural-voice.md +0 -930
- package/templates/resources/styles/web-novel.md +0 -525
- package/templates/skills/analysis/character-analysis/SKILL.md +0 -71
- package/templates/skills/analysis/foreshadow-analysis/SKILL.md +0 -45
- package/templates/skills/analysis/hook-analysis/SKILL.md +0 -111
- package/templates/skills/analysis/logic-analysis/SKILL.md +0 -58
- package/templates/skills/analysis/opening-analysis/SKILL.md +0 -59
- package/templates/skills/analysis/pacing-analysis/SKILL.md +0 -55
- package/templates/skills/analysis/power-analysis/SKILL.md +0 -148
- package/templates/skills/analysis/reader-analysis/SKILL.md +0 -117
- package/templates/skills/analysis/style-analysis/SKILL.md +0 -60
- package/templates/skills/analysis/voice-analysis/SKILL.md +0 -42
- package/templates/skills/auto-tracking/SKILL.md +0 -280
- package/templates/skills/genre-knowledge/fantasy/SKILL.md +0 -355
- package/templates/skills/genre-knowledge/mystery/SKILL.md +0 -337
- package/templates/skills/genre-knowledge/romance/SKILL.md +0 -228
- package/templates/skills/genre-knowledge/sci-fi/SKILL.md +0 -65
- package/templates/skills/genre-knowledge/thriller/SKILL.md +0 -95
- package/templates/skills/planning/volume-detail/SKILL.md +0 -219
- package/templates/skills/quality-assurance/consistency-checker/SKILL.md +0 -412
- package/templates/skills/quality-assurance/continuity-tracker/SKILL.md +0 -157
- package/templates/skills/quality-assurance/facts-checker/SKILL.md +0 -405
- package/templates/skills/quality-assurance/forgotten-elements/SKILL.md +0 -147
- package/templates/skills/quality-assurance/getting-started/SKILL.md +0 -224
- package/templates/skills/quality-assurance/hook-checker/SKILL.md +0 -164
- package/templates/skills/quality-assurance/hook-checker/experts/hook-analyst.md +0 -33
- package/templates/skills/quality-assurance/long-series-continuity/SKILL.md +0 -570
- package/templates/skills/quality-assurance/pacing-monitor/SKILL.md +0 -143
- package/templates/skills/quality-assurance/pov-validator/SKILL.md +0 -135
- package/templates/skills/quality-assurance/pre-write-checklist/SKILL.md +0 -583
- package/templates/skills/quality-assurance/requirement-detector/CONFLICT_RESOLUTION.md +0 -119
- package/templates/skills/quality-assurance/requirement-detector/EXAMPLES.md +0 -146
- package/templates/skills/quality-assurance/requirement-detector/KEYWORDS.md +0 -160
- package/templates/skills/quality-assurance/requirement-detector/SKILL.md +0 -149
- package/templates/skills/quality-assurance/setting-detector/SKILL.md +0 -611
- package/templates/skills/quality-assurance/style-detector/CONFLICT_RESOLUTION.md +0 -126
- package/templates/skills/quality-assurance/style-detector/EXAMPLES.md +0 -206
- package/templates/skills/quality-assurance/style-detector/KEYWORDS.md +0 -207
- package/templates/skills/quality-assurance/style-detector/SKILL.md +0 -264
- package/templates/skills/quality-assurance/voice-consistency-checker/SKILL.md +0 -103
- package/templates/skills/quality-assurance/voice-consistency-checker/experts/voice-analyst.md +0 -21
- package/templates/skills/quality-assurance/workflow-guide/SKILL.md +0 -381
- package/templates/skills/writing-techniques/character-arc/SKILL.md +0 -267
- package/templates/skills/writing-techniques/dialogue-techniques/SKILL.md +0 -366
- package/templates/skills/writing-techniques/multi-thread-narrative/SKILL.md +0 -708
- package/templates/skills/writing-techniques/multi-thread-narrative/experts/thread-analyst.md +0 -226
- package/templates/skills/writing-techniques/pacing-control/SKILL.md +0 -480
- package/templates/skills/writing-techniques/reader-expectation/SKILL.md +0 -1026
- package/templates/skills/writing-techniques/reader-expectation/experts/expectation-analyst.md +0 -209
- package/templates/skills/writing-techniques/revision-polish/SKILL.md +0 -496
- package/templates/skills/writing-techniques/revision-polish/experts/revision-editor.md +0 -221
- package/templates/skills/writing-techniques/scene-structure/SKILL.md +0 -361
- package/templates/skills/writing-techniques/style-learning/SKILL.md +0 -436
- package/templates/skills/writing-techniques/writing-balance/.gitkeep +0 -0
- package/templates/skills/writing-techniques/writing-balance/SKILL.md +0 -460
- package/templates/skills/writing-techniques/writing-techniques/SKILL.md +0 -727
- package/templates/tracking/story-facts.json +0 -5
- package/templates/tracking/summary/characters-summary.json +0 -7
- package/templates/tracking/summary/plot-summary.json +0 -13
- package/templates/tracking/summary/timeline-summary.json +0 -8
- package/templates/tracking/summary/volume-summaries.json +0 -5
- package/templates/tracking/tracking-log.md +0 -110
- package/templates/tracking/validation-rules.json +0 -128
- /package/templates/resources/{memory/constitution.md → constitution.md} +0 -0
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# 测试中文字数统计功能
|
|
4
|
-
# 用于验证 count_chinese_words 函数的准确性
|
|
5
|
-
|
|
6
|
-
set -e
|
|
7
|
-
|
|
8
|
-
# Source common functions
|
|
9
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
|
-
source "$SCRIPT_DIR/common.sh"
|
|
11
|
-
|
|
12
|
-
# 颜色输出
|
|
13
|
-
GREEN='\033[0;32m'
|
|
14
|
-
RED='\033[0;31m'
|
|
15
|
-
YELLOW='\033[1;33m'
|
|
16
|
-
NC='\033[0m' # No Color
|
|
17
|
-
|
|
18
|
-
echo "========================================"
|
|
19
|
-
echo "中文字数统计功能测试"
|
|
20
|
-
echo "========================================"
|
|
21
|
-
echo ""
|
|
22
|
-
|
|
23
|
-
# 创建临时测试文件
|
|
24
|
-
TEST_DIR=$(mktemp -d)
|
|
25
|
-
trap "rm -rf $TEST_DIR" EXIT
|
|
26
|
-
|
|
27
|
-
# 测试用例1: 纯中文文本
|
|
28
|
-
echo "## 测试1: 纯中文文本"
|
|
29
|
-
cat > "$TEST_DIR/test1.md" << 'EOF'
|
|
30
|
-
今天天气很好,我去公园散步。
|
|
31
|
-
看到很多人在锻炼身体。
|
|
32
|
-
EOF
|
|
33
|
-
expected1=16
|
|
34
|
-
actual1=$(count_chinese_words "$TEST_DIR/test1.md")
|
|
35
|
-
echo " 预期字数: $expected1"
|
|
36
|
-
echo " 实际字数: $actual1"
|
|
37
|
-
if [ "$actual1" -eq "$expected1" ]; then
|
|
38
|
-
echo -e " ${GREEN}✅ 测试通过${NC}"
|
|
39
|
-
else
|
|
40
|
-
echo -e " ${RED}❌ 测试失败${NC}"
|
|
41
|
-
fi
|
|
42
|
-
echo ""
|
|
43
|
-
|
|
44
|
-
# 测试用例2: 包含Markdown标记
|
|
45
|
-
echo "## 测试2: 包含Markdown标记的文本"
|
|
46
|
-
cat > "$TEST_DIR/test2.md" << 'EOF'
|
|
47
|
-
# 第一章
|
|
48
|
-
|
|
49
|
-
这是**重要**的内容。
|
|
50
|
-
|
|
51
|
-
- 列表项1
|
|
52
|
-
- 列表项2
|
|
53
|
-
|
|
54
|
-
> 这是引用
|
|
55
|
-
EOF
|
|
56
|
-
# 实际内容: 第一章这是重要的内容列表项1列表项2这是引用
|
|
57
|
-
expected2=21
|
|
58
|
-
actual2=$(count_chinese_words "$TEST_DIR/test2.md")
|
|
59
|
-
echo " 预期字数: $expected2"
|
|
60
|
-
echo " 实际字数: $actual2"
|
|
61
|
-
if [ "$actual2" -eq "$expected2" ]; then
|
|
62
|
-
echo -e " ${GREEN}✅ 测试通过${NC}"
|
|
63
|
-
else
|
|
64
|
-
echo -e " ${YELLOW}⚠️ 字数差异: $((actual2 - expected2))${NC}"
|
|
65
|
-
fi
|
|
66
|
-
echo ""
|
|
67
|
-
|
|
68
|
-
# 测试用例3: 中英混合
|
|
69
|
-
echo "## 测试3: 中英文混合文本"
|
|
70
|
-
cat > "$TEST_DIR/test3.md" << 'EOF'
|
|
71
|
-
这是一个测试test文件。
|
|
72
|
-
包含123数字和English单词。
|
|
73
|
-
EOF
|
|
74
|
-
# 实际内容(移除空格和标点后): 这是一个测试test文件包含123数字和English单词
|
|
75
|
-
expected3=27
|
|
76
|
-
actual3=$(count_chinese_words "$TEST_DIR/test3.md")
|
|
77
|
-
echo " 预期字数: 约$expected3"
|
|
78
|
-
echo " 实际字数: $actual3"
|
|
79
|
-
if [ "$actual3" -ge 20 ] && [ "$actual3" -le 35 ]; then
|
|
80
|
-
echo -e " ${GREEN}✅ 测试通过(在合理范围内)${NC}"
|
|
81
|
-
else
|
|
82
|
-
echo -e " ${YELLOW}⚠️ 字数差异较大${NC}"
|
|
83
|
-
fi
|
|
84
|
-
echo ""
|
|
85
|
-
|
|
86
|
-
# 测试用例4: 包含代码块
|
|
87
|
-
echo "## 测试4: 包含代码块的文本"
|
|
88
|
-
cat > "$TEST_DIR/test4.md" << 'EOF'
|
|
89
|
-
这是正常文本。
|
|
90
|
-
|
|
91
|
-
```javascript
|
|
92
|
-
console.log("这是代码不应该被计数");
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
这是结尾文本。
|
|
96
|
-
EOF
|
|
97
|
-
expected4=12
|
|
98
|
-
actual4=$(count_chinese_words "$TEST_DIR/test4.md")
|
|
99
|
-
echo " 预期字数: $expected4"
|
|
100
|
-
echo " 实际字数: $actual4"
|
|
101
|
-
if [ "$actual4" -eq "$expected4" ]; then
|
|
102
|
-
echo -e " ${GREEN}✅ 测试通过${NC}"
|
|
103
|
-
else
|
|
104
|
-
echo -e " ${YELLOW}⚠️ 字数差异: $((actual4 - expected4))${NC}"
|
|
105
|
-
fi
|
|
106
|
-
echo ""
|
|
107
|
-
|
|
108
|
-
# 对比测试: wc -w vs 新方法
|
|
109
|
-
echo "## 对比测试: wc -w vs count_chinese_words"
|
|
110
|
-
cat > "$TEST_DIR/compare.md" << 'EOF'
|
|
111
|
-
这是一个包含大约五十个字的测试文本。
|
|
112
|
-
我们需要验证字数统计的准确性。
|
|
113
|
-
使用wc命令统计中文字数是不准确的。
|
|
114
|
-
应该使用专门的中文字数统计方法。
|
|
115
|
-
这样才能得到正确的结果。
|
|
116
|
-
EOF
|
|
117
|
-
wc_result=$(wc -w < "$TEST_DIR/compare.md" | tr -d ' ')
|
|
118
|
-
new_result=$(count_chinese_words "$TEST_DIR/compare.md")
|
|
119
|
-
echo " wc -w 结果: $wc_result (不准确)"
|
|
120
|
-
echo " 新方法结果: $new_result (准确)"
|
|
121
|
-
echo -e " ${YELLOW}注意:wc -w 对中文统计极不准确!${NC}"
|
|
122
|
-
echo ""
|
|
123
|
-
|
|
124
|
-
# 性能测试
|
|
125
|
-
echo "## 性能测试: 大文件处理"
|
|
126
|
-
cat > "$TEST_DIR/large.md" << 'EOF'
|
|
127
|
-
# 第一章:开始
|
|
128
|
-
|
|
129
|
-
今天是个好天气,阳光明媚,万里无云。
|
|
130
|
-
小明决定去公园散步,顺便思考一下人生。
|
|
131
|
-
他一边走一边想,不知不觉来到了湖边。
|
|
132
|
-
湖水清澈见底,几只野鸭在水面游弋。
|
|
133
|
-
远处传来孩子们的欢笑声,让人心情愉悦。
|
|
134
|
-
|
|
135
|
-
## 第二节
|
|
136
|
-
|
|
137
|
-
突然,他看到一位老人坐在长椅上。
|
|
138
|
-
老人面带微笑,似乎在等待什么。
|
|
139
|
-
小明走上前去,礼貌地打了个招呼。
|
|
140
|
-
老人抬起头,慈祥的目光看向小明。
|
|
141
|
-
两人开始了一段有趣的对话。
|
|
142
|
-
|
|
143
|
-
**重要的转折点**:
|
|
144
|
-
- 老人讲述了一个神奇的故事
|
|
145
|
-
- 小明意识到生活的意义
|
|
146
|
-
- 他决定改变自己的人生轨迹
|
|
147
|
-
|
|
148
|
-
最后,夕阳西下,小明告别了老人。
|
|
149
|
-
他的内心充满了力量和希望。
|
|
150
|
-
这次偶遇,改变了他的一生。
|
|
151
|
-
EOF
|
|
152
|
-
|
|
153
|
-
start_time=$(date +%s%N)
|
|
154
|
-
large_count=$(count_chinese_words "$TEST_DIR/large.md")
|
|
155
|
-
end_time=$(date +%s%N)
|
|
156
|
-
elapsed=$((($end_time - $start_time) / 1000000)) # 转换为毫秒
|
|
157
|
-
|
|
158
|
-
echo " 文件字数: $large_count"
|
|
159
|
-
echo " 处理时间: ${elapsed}ms"
|
|
160
|
-
if [ "$elapsed" -lt 1000 ]; then
|
|
161
|
-
echo -e " ${GREEN}✅ 性能良好${NC}"
|
|
162
|
-
else
|
|
163
|
-
echo -e " ${YELLOW}⚠️ 处理时间较长${NC}"
|
|
164
|
-
fi
|
|
165
|
-
echo ""
|
|
166
|
-
|
|
167
|
-
# 总结
|
|
168
|
-
echo "========================================"
|
|
169
|
-
echo "测试完成!"
|
|
170
|
-
echo "========================================"
|
|
171
|
-
echo ""
|
|
172
|
-
echo -e "${GREEN}核心功能:${NC}"
|
|
173
|
-
echo " ✓ 准确统计中文字符"
|
|
174
|
-
echo " ✓ 排除Markdown标记"
|
|
175
|
-
echo " ✓ 排除代码块"
|
|
176
|
-
echo " ✓ 处理混合文本"
|
|
177
|
-
echo ""
|
|
178
|
-
echo -e "${YELLOW}使用建议:${NC}"
|
|
179
|
-
echo " • 不要使用 'wc -w' 统计中文字数"
|
|
180
|
-
echo " • 使用 'count_chinese_words' 函数获得准确结果"
|
|
181
|
-
echo " • 在写作完成后验证字数是否达标"
|
|
182
|
-
echo ""
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# 性能对比测试:预加载缓存 vs 重复 stat 调用
|
|
4
|
-
|
|
5
|
-
echo "=== 性能对比测试 ==="
|
|
6
|
-
echo ""
|
|
7
|
-
|
|
8
|
-
# 测试文件列表
|
|
9
|
-
files=(
|
|
10
|
-
"resources/config/keyword-mappings.json"
|
|
11
|
-
"templates/scripts/bash/check-writing-state.sh"
|
|
12
|
-
"templates/scripts/bash/common.sh"
|
|
13
|
-
"resources/craft/dialogue.md"
|
|
14
|
-
"resources/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 (取决于文件数量和磁盘速度)"
|
|
@@ -1,199 +0,0 @@
|
|
|
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 "所有测试通过!缓存语义修复成功。"
|
|
@@ -1,35 +0,0 @@
|
|
|
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="resources/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)"
|
|
@@ -1,60 +0,0 @@
|
|
|
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 边界情况测试通过"
|
|
@@ -1,28 +0,0 @@
|
|
|
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 缓存测试全部通过"
|