refactor: enforce 800 line source limits

This commit is contained in:
caoxiaozhu
2026-06-22 11:58:53 +08:00
parent 08a4fa3577
commit 6d33ba5742
150 changed files with 27413 additions and 23791 deletions

View File

@@ -35,14 +35,44 @@ const assistantScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/TravelReimbursementCreateView.js', import.meta.url)),
'utf8'
)
const assistantCreateStateScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementCreateViewState.js', import.meta.url)),
'utf8'
)
const assistantCreateLifecycleScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementCreateViewLifecycle.js', import.meta.url)),
'utf8'
)
const assistantCreateControlsScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementCreateViewControls.js', import.meta.url)),
'utf8'
)
const assistantMessageActionsScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementMessageActions.js', import.meta.url)),
'utf8'
)
const assistantSubmitComposerScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementSubmitComposer.js', import.meta.url)),
'utf8'
)
const assistantSubmitResponseModelScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/travelReimbursementSubmitResponseModel.js', import.meta.url)),
'utf8'
)
const assistantSessionStateScript = readFileSync(
fileURLToPath(new URL('../src/views/scripts/useTravelReimbursementSessionState.js', import.meta.url)),
'utf8'
)
const assistantSurface = [
assistantScript,
assistantCreateStateScript,
assistantCreateLifecycleScript,
assistantCreateControlsScript,
assistantMessageActionsScript,
assistantSubmitComposerScript,
assistantSubmitResponseModelScript,
assistantSessionStateScript
].join('\n')
const assistantTemplate = readFileSync(
fileURLToPath(new URL('../src/views/TravelReimbursementCreateView.vue', import.meta.url)),
'utf8'
@@ -146,7 +176,7 @@ test('application entry keeps its own assistant source without creating a separa
assert.match(appShellComposable, /function openExpenseApplicationCreate\(\) \{[\s\S]*openFinancialAssistantCreate\(SMART_ENTRY_SOURCE_APPLICATION\)/)
assert.match(appShellComposable, /function openTravelCreate\(\) \{[\s\S]*openFinancialAssistantCreate\(SMART_ENTRY_SOURCE_REIMBURSEMENT\)/)
assert.match(appShellComposable, /openExpenseApplicationCreate,/)
assert.match(assistantScript, /activeSessionType\.value === SESSION_TYPE_APPLICATION[\s\S]*我想先申请一笔差旅费用/)
assert.match(assistantSurface, /activeSessionType\.value === SESSION_TYPE_APPLICATION[\s\S]*我想先申请一笔差旅费用/)
})
test('application edit prefill opens assistant without auto submit', () => {
@@ -165,23 +195,23 @@ test('application edit prefill opens assistant without auto submit', () => {
/initialApplicationPreview:\s*\{[\s\S]*type:\s*Object[\s\S]*default:\s*null/
)
assert.match(
assistantScript,
assistantSurface,
/props\.initialApplicationPreview[\s\S]*normalizeApplicationPreview\(props\.initialApplicationPreview\)[\s\S]*createMessage\('assistant', buildLocalApplicationPreviewMessage\(applicationPreview\)/
)
assert.match(assistantSessionStateScript, /&& !props\.initialApplicationPreview/)
assert.match(
assistantScript,
assistantSurface,
/if \(props\.initialPromptAutoSubmit !== false\) \{[\s\S]*submitComposer\(\)/
)
})
test('financial assistant toolbar renders isolated assistant sessions without steward entry', () => {
assert.match(assistantScript, /filterAssistantSessionModes\(ASSISTANT_SESSION_MODE_OPTIONS, currentUser\.value\)/)
assert.match(assistantScript, /\.filter\(\(mode\) => mode\.key !== SESSION_TYPE_STEWARD\)/)
assert.match(assistantScript, /mode\.key === SESSION_TYPE_BUDGET/)
assert.match(assistantScript, /visibleModes\.map/)
assert.match(assistantScript, /targetSessionType:\s*mode\.key/)
assert.match(assistantScript, /active:\s*mode\.key === activeSessionType\.value/)
assert.match(assistantSurface, /filterAssistantSessionModes\(ASSISTANT_SESSION_MODE_OPTIONS, currentUser\.value\)/)
assert.match(assistantSurface, /\.filter\(\(mode\) => mode\.key !== SESSION_TYPE_STEWARD\)/)
assert.match(assistantSurface, /mode\.key === SESSION_TYPE_BUDGET/)
assert.match(assistantSurface, /visibleModes\.map/)
assert.match(assistantSurface, /targetSessionType:\s*mode\.key/)
assert.match(assistantSurface, /active:\s*mode\.key === activeSessionType\.value/)
assert.match(assistantTemplate, /:class="\{ active: shortcut\.active \}"/)
assert.match(assistantTemplate, /:aria-pressed="shortcut\.active \? 'true' : 'false'"/)
assert.match(assistantTemplate, /:disabled="shortcut\.active \|\| submitting/)
@@ -193,8 +223,8 @@ test('closing a busy assistant keeps the running instance recoverable', () => {
assert.match(appShellComposable, /if \(smartEntryOpen\.value\) \{\s*smartEntryRevealToken\.value \+= 1\s*return\s*\}/)
assert.match(appShellComposable, /smartEntryRevealToken,/)
assert.match(assistantScript, /reopenToken:\s*\{\s*type:\s*Number/)
assert.match(assistantScript, /closeAfterBusy\.value = false[\s\S]*workbenchVisible\.value = true/)
assert.match(assistantScript, /function emitCloseAfterLeave\(\) \{\s*if \(workbenchVisible\.value\)/)
assert.match(assistantSurface, /closeAfterBusy\.value = false[\s\S]*workbenchVisible\.value = true/)
assert.match(assistantSurface, /function emitCloseAfterLeave\(\) \{\s*if \(workbenchVisible\.value\)/)
})
test('financial assistant welcome copy differentiates application intent from reimbursement entry', () => {
@@ -259,22 +289,22 @@ test('assistant message action toolbar collects lightweight feedback', () => {
assert.match(messageItemTemplate, /mdi mdi-thumb-down-outline/)
assert.match(assistantScript, /emits:\s*\['close', 'draft-saved', 'request-updated'\]/)
assert.match(appShellRouteView, /@request-updated="handleRequestUpdated"/)
assert.match(assistantScript, /function buildMessageOperationFeedbackContext/)
assert.match(assistantScript, /source:\s*'assistant_message_action'/)
assert.match(assistantScript, /operation_type:\s*message\?\.stewardPlan \? 'steward_message' : 'assistant_message'/)
assert.match(assistantScript, /function shouldShowAssistantMessageActions/)
assert.match(assistantScript, /function copyAssistantMessage/)
assert.match(assistantScript, /function speakAssistantMessage/)
assert.match(assistantScript, /function isMessageFeedbackSelected/)
assert.match(assistantScript, /function submitOperationFeedbackForMessage/)
assert.match(assistantScript, /createOperationFeedback/)
assert.match(assistantScript, /normalizeOperationFeedbackContext/)
assert.match(assistantScript, /submitted:\s*true/)
assert.match(assistantScript, /dismissed:\s*false/)
assert.doesNotMatch(assistantScript, /emit\('operation-completed'/)
assert.match(assistantSurface, /function buildMessageOperationFeedbackContext/)
assert.match(assistantSurface, /source:\s*'assistant_message_action'/)
assert.match(assistantSurface, /operation_type:\s*message\?\.stewardPlan \? 'steward_message' : 'assistant_message'/)
assert.match(assistantSurface, /function shouldShowAssistantMessageActions/)
assert.match(assistantSurface, /function copyAssistantMessage/)
assert.match(assistantSurface, /function speakAssistantMessage/)
assert.match(assistantSurface, /function isMessageFeedbackSelected/)
assert.match(assistantSurface, /function submitOperationFeedbackForMessage/)
assert.match(assistantSurface, /createOperationFeedback/)
assert.match(assistantSurface, /normalizeOperationFeedbackContext/)
assert.match(assistantSurface, /submitted:\s*true/)
assert.match(assistantSurface, /dismissed:\s*false/)
assert.doesNotMatch(assistantSurface, /emit\('operation-completed'/)
assert.match(assistantSubmitComposerScript, /emitOperationCompleted\?\.\(payload/)
assert.match(assistantSubmitComposerScript, /operationFeedback:\s*buildOperationFeedbackState/)
assert.match(assistantSubmitComposerScript, /rating:\s*0/)
assert.match(assistantSubmitResponseModelScript, /rating:\s*0/)
const context = normalizeOperationFeedbackContext(
{