Update dialect tests for UTC timestamp functions and cleaner-handler
test for runCleaner's extended parameter signature.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Record ALL input orders in history, including resolution failures (not_found)
and ERP query misses (erp_not_found). Add ProductionId column to track original
总排号 input. Add 总排号 column and new status styles to the history UI. Fix
empty result caching that prevented retry on transient query failures.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Record materials not in the deletion list as "skipped" with reason
instead of just logging them. Skip inserting material details to
database during dry runs to avoid phantom records.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Admin can now pass selectedManagers to getCleanerData so material codes
are queried from MaterialsToBeDeleted by ManagerName IN (selectedManagers).
When no managers are selected, fallback to DiscreteMaterialPlanData by
orderNumbers. User behavior is unchanged. Includes updated tests and
role-based flow documentation.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace magic strings with AuditAction/AuditStatus enums across all consumers,
add logAuditWithCurrentUser() convenience wrapper, extend audit coverage to
data import, result export, app update, and ERP credentials operations, and
harden crash handlers with try/catch to prevent audit failures from cascading.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Switch extractor-workflow e2e test from vitest to Playwright test runner
for consistency with playwright.config.ts. Remove redundant unit tests
(cleaner, erp-auth, extractor) that have been superseded by more thorough
replacements under tests/unit/services/erp/. Enable test isolation
unconditionally to prevent cross-file state pollution.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add connected-path tests for mysql, sql-server, and postgresql using
mocked drivers (mysql2/promise, mssql, pg) covering
connect, query, transaction, and disconnect scenarios
- Fix tautological assertion in auth-flow.test.ts (hasError >= 0 was always true)
- Add tests/integration to vitest exclude list to prevent
module cache pollution under isolate:false
- Set isolate to true for CI, false for local dev (was: isolate false)
Replace fragile module-level let variables and SQL string parsing
with vi.hoisted() mock functions that are reset and configured
per-test in beforeEach via mockResolvedValue/mockResolvedValueOnce.
- Remove 8 module-level mutable state variables
- Remove matchQuery() SQL parser
- Use vi.hoisted() for shared mock functions across vi.mock() factories
- Each test explicitly controls mock return values with mockResolvedValueOnce
- Fix getCleanerData error test to use direct mock instead of dynamic import
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix logger mock missing default export in extractor.test.ts
- Fix performance-monitor mock configuration
- Fix prefer-const in validation-database.test.ts
- Fix no-unsafe-function-type in cleaner-handler.test.ts
- Fix no-empty-function in cleaner-application-service.test.ts
- Run prettier format on test files
All 622 tests now passing (59 files, 3 skipped)
- Add logger/error-utils mocks to cleaner-handler test to suppress IPC error log noise
- Move setupServiceMocks into beforeEach for consistent default mocking in cleaner tests
- Replace vi.waitFor (2s timeout) with setImmediate microtask flush in extractor test
- Remove dead activeType assignments in validation-database test
- Align TestUser.id type with UserInfo.id (string → number) and use deterministic counter
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add unit tests for core ERP service modules including ErpBrowserManager,
cleaner, erp-auth, extractor-core, extractor, and order-resolver. Also
includes test coverage improvement plan and quality review report.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove unused imports (run, trackDuration, PerformanceTracker,
ConfigManager, disconnectDb) flagged by ESLint
- Remove unused isSlow variable in performance-monitor catch block
- Add eslint-disable for require() in Playwright JS script
- Fix logger-performance test flakiness by using vi.resetModules()
with dynamic imports to prevent cached logger references across
test files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add prepareSql() to PostgreSqlService that quotes unquoted column names
before execution. PostgreSQL lowercases unquoted identifiers, but
SSMA-migrated tables have uppercase column names requiring double-quoting.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add three SqlDialect implementations with a factory function:
- MySqlDialect: positional ?, ON DUPLICATE KEY UPDATE, LIMIT/OFFSET
- SqlServerDialect: @pN params, MERGE USING, OFFSET/FETCH
- PostgreSqlDialect: $N (1-based), ON CONFLICT DO UPDATE, LIMIT/OFFSET
TDD approach: 43 tests written first, all passing.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix logger-performance test mock path to use bare module specifier
- Replace meaningless "should be defined" assertions in repositories test
with behavior-based tests covering upsert, batch operations, queries,
deletes, and error handling for both MaterialsToBeDeletedRepository
and DiscreteMaterialPlanRepository
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The shouldDeleteMaterial tests had a mockCleaner that reimplemented the
production logic inline, meaning bugs in the real code would never be caught.
Now uses an actual CleanerService instance instead.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Refactor logger.test.ts to mock logger module directly instead of winston
- Move vi.resetModules() to beforeEach to avoid module cache pollution
- Simplify mock structure to avoid conflicts with logger-performance.test.ts
- All 335 tests now pass (44 files)
Replace toBeDefined()/typeof checks with assertions that verify actual
behavior and output content. Key changes:
- locators: assert actual CSS selector values instead of existence
- logger-integration: test run()/getContext()/withRequestContext() behavior
- logger: verify winstonCalls content (level, message, metadata)
- config-manager: test default values, singleton, and getConfig() throws
- erp-auth: remove empty Class Structure block (covered by behavior tests)
- audit-logger: spy on auditLogger.info to verify JSONL entry content
- extractor: remove Math.ceil tests, verify error result structure
Net: -209 lines of hollow/redundant test code.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The vi.mock('fs') factory returned { default: { ... } } causing fs.mkdirSync
to be undefined at runtime. Add top-level exports alongside default for ESM/CJS interop.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Replace 4x expect(true).toBe(true) in audit-logger.test.ts with
applyAuditConfig() + app.getVersion call count assertions
- Replace if(!hasCredentials){return} pattern with it.skipIf() in
3 integration test files (cleaner, erp-auth, extractor) so Vitest
correctly reports 12 tests as "skipped" instead of "passed"
- Remove placeholder assertion from skipped update-service test
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Enhance ERP automation error diagnostics by capturing PNG screenshots
on every error and forwarding browser console warnings/errors to the
structured logger. Includes automatic cleanup of old screenshots
aligned with the configured log retention period.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove misleading await from audit-logger tests (functions are sync)
- Add cleanup() to LoggerAPI type definition in index.d.ts
- Fix circular reference fallback to preserve null values
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Make logAudit and closeAuditLogger synchronous (were async for no reason)
- Set audit-logger silent:true initially, enable on applyAuditConfig()
- Add try-catch for circular references in consoleFormat meta JSON
- Update all callers to remove unnecessary await/.catch() on sync functions
- Add comment to shared.ts explaining acceptable sync FS usage
- Fix audit-logger test for sync closeAuditLogger
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change the protected row number range from 7000-7999 to 2000-7999 to prevent deletion of materials in this broader range.
- Updated isMaterialDeletable() method logic
- Updated getSkipReason() error messages
- Updated test cases to reflect new range boundaries
- Updated documentation templates and error collection guide
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add *.yaml text eol=lf rule to .gitattributes for consistent line endings
- Format cleaner.ts with Prettier (parameter and chain formatting)
- Format CleanerPage.tsx (JSX formatting)
- Format cleaner.test.ts (array formatting)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit integrates the logging infrastructure across the entire application:
IPC Layer:
- Add logger-handler.ts with centralized IPC logging channels
- Integrate audit logging into auth, cleaner, extractor handlers
- Add structured logging for IPC operations and data flow
Service Layer:
- Add logger integration to ERP services (extractor, cleaner)
- Integrate logging into excel-parser and user DAO
- Add operation tracking and error logging
Renderer Layer:
- Add useLogger hook for component-level logging
- Update App.tsx with session and user activity logging
- Enable frontend audit trail for critical actions
Testing:
- Add comprehensive IPC logging integration tests
- Enhance unit test coverage for logger and audit-logger
- Add end-to-end logging flow validation
Types:
- Update preload type definitions for logging APIs
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>