Commit 5b995e61 by 张立顺

feat 日报模板调整

1 parent 9800e969
# Fix Test Blockers and Module Boundary Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Remove the stale marketing flag assertion and dynamic-form ESM/CommonJS cycle so the Windows-compatible npm test chain can progress through the real suites.
**Architecture:** Keep the active-only marketing map contract and test its public resolver. Align the ESM-dominant form-engine boundary by converting only the show-rule visibility modules and their tests to ESM; then repair any independently reproduced CommonJS mock re-entry at the narrowest dependency boundary.
**Tech Stack:** Node.js 20 built-in test runner, JavaScript ESM/CommonJS, npm scripts, WeChat mini-program source.
## Global Constraints
- Work on the current branch because the user explicitly declined a separate branch/worktree.
- Do not add a root `"type": "module"` declaration.
- Do not change marketing flag production behavior.
- Do not alter form visibility or payload behavior.
- Treat unrelated date and `wx` failures as separate issues.
- This small repair does not require a migration manifest.
---
### Task 1: Correct the marketing flag behavior test
**Files:**
- Modify: `tests/marketingFlag.test.mjs`
- Verify: `utils/marketingFlag.js`
**Interfaces:**
- Consumes: `buildMarketingFlagMap(list)` and `resolveMarketingFlag(map, goods)`.
- Produces: a regression test for active-only indexing and inactive fallback to `0`.
- [ ] **Step 1: Preserve the observed failing evidence**
Run: `node --test tests/marketingFlag.test.mjs`
Expected: FAIL because `map['200']` is `undefined`, not `0`.
- [ ] **Step 2: Replace the private representation assertion**
Update the first test to assert `map['200'] === undefined` and `resolveMarketingFlag(map, { merchantGoodsId: 200 }) === 0`. Rename the test so it states that only active goods are indexed and inactive goods resolve to zero.
- [ ] **Step 3: Verify the corrected behavior test**
Run: `node --test tests/marketingFlag.test.mjs`
Expected: PASS with no production change.
### Task 2: Remove the core show-rule module cycle
**Files:**
- Modify: `packageDynamicForm/form-engine/group-visibility.js`
- Modify: `packageDynamicForm/form-engine/show-rule-context.js`
- Modify: `packageDynamicForm/tests/group-show-rule-eval.test.mjs`
- Modify: `packageDynamicForm/tests/group-show-rule-eval-fallback.test.mjs`
- Modify: `packageDynamicForm/tests/app-show-rule-parity.test.mjs`
- Modify: `packageDynamicForm/tests/form-engine.test.mjs`
**Interfaces:**
- Consumes: `evaluateShowRule(keys, resultExpr, rowFields, resolver)` and `resolveShowRuleContextValue(key, pageContext)`.
- Produces: named ESM exports `isGroupChildVisibleInRow`, `filterVisibleRowFields`, `resolveShowRuleSceneCodes`, `resolveShowRuleBrandIds`, and `resolveShowRuleContextValue` with unchanged signatures.
- [ ] **Step 1: Preserve focused failing evidence**
Run: `node --test packageDynamicForm/tests/group-show-rule-eval.test.mjs packageDynamicForm/tests/store-v230-context-visibility.test.mjs packageDynamicForm/tests/form-engine.test.mjs`
Expected: FAIL with `ERR_REQUIRE_CYCLE_MODULE` through `group-visibility.js`.
- [ ] **Step 2: Convert the visibility boundary to ESM**
Use static imports in `group-visibility.js`, export both public functions, and convert the three context functions in `show-rule-context.js` to named ESM exports. Do not change their logic.
- [ ] **Step 3: Convert test-only synchronous requires**
Replace `createRequire()` calls for `group-show-rule-eval.js` and `group-visibility.js` with ESM imports. Keep CommonJS fixture/config requires unchanged.
- [ ] **Step 4: Verify the focused cycle tests**
Run the Step 1 command again.
Expected: the show-rule `ERR_REQUIRE_CYCLE_MODULE` no longer appears; tests either pass or reveal an independent mock re-entry.
### Task 3: Repair a reproduced mock submit-adapter re-entry
**Files:**
- Modify only the affected files selected by the focused failure among:
- `packageDynamicForm/api/mockDetailJsonContent.js`
- `packageDynamicForm/api/mockDynamicDetail.js`
- `packageDynamicForm/api/mockStoreDynamicDetail.js`
- corresponding `packageDynamicForm/tests/*.test.mjs`
**Interfaces:**
- Consumes: mock detail builders and existing `submit-adapter.js` exported transformations.
- Produces: identical mock response shapes without synchronously requiring an ESM module that is still initializing.
- [ ] **Step 1: Reproduce after Task 2**
Run: `node --test packageDynamicForm/tests/form-engine.test.mjs packageDynamicForm/tests/dailyReportSaveRequest.test.mjs packageDynamicForm/tests/staffDailyReportDetail.test.mjs packageDynamicForm/tests/storeDailyReportDetail.test.mjs`
Expected: if still affected, FAIL with `ERR_REQUIRE_CYCLE_MODULE` naming `submit-adapter.js`; otherwise skip the remaining steps in this task.
- [ ] **Step 2: Add or preserve a focused behavioral test**
Use the existing mock detail tests to assert non-empty normalized detail data and valid `jsonContent`. The regression fails before the boundary repair because the module cannot initialize.
- [ ] **Step 3: Apply the narrowest boundary repair**
Remove only the synchronous CommonJS-to-ESM re-entry proven by Step 1. Preserve `buildMockDetailJsonContent`, staff/store mock constants, and response shapes.
- [ ] **Step 4: Verify focused mock tests**
Run the Step 1 command again.
Expected: PASS without `ERR_REQUIRE_CYCLE_MODULE`.
### Task 4: Regression verification
**Files:**
- Review: all modified files with `git diff --check` and `git diff`.
**Interfaces:**
- Consumes: completed repairs from Tasks 1-3.
- Produces: fresh evidence for the original symptoms and the repository test chain.
- [ ] **Step 1: Run focused tests**
Run: `node --test tests/marketingFlag.test.mjs packageDynamicForm/tests/group-show-rule-eval.test.mjs packageDynamicForm/tests/group-show-rule-eval-fallback.test.mjs packageDynamicForm/tests/app-show-rule-parity.test.mjs packageDynamicForm/tests/store-v230-context-visibility.test.mjs`
- [ ] **Step 2: Run the dynamic-form suite**
Run: `npm run test:dynamicForm`
- [ ] **Step 3: Run the root suite**
Run: `npm test`
- [ ] **Step 4: Inspect the patch**
Run: `git diff --check` and `git status --short`.
Expected: no whitespace errors; report any independent test blockers exactly as observed.
# Test Blockers and Module Boundary Design
## Context
The cross-platform npm test scripts now reach the real test suites on Windows. Two pre-existing failures block the root test chain:
1. `tests/marketingFlag.test.mjs` expects an inactive goods entry to be materialized as `0`, while `buildMarketingFlagMap()` intentionally stores active goods only and callers use `resolveMarketingFlag()` to turn missing entries into `0`.
2. `packageDynamicForm` mixes ESM imports with synchronous CommonJS `require()` calls across the same form-engine dependency graph. Node 20 rejects the ESM -> CommonJS -> ESM re-entry with `ERR_REQUIRE_CYCLE_MODULE`.
This is a small repair, not a cross-project migration or large refactor, so the repository migration manifest gate does not apply.
## Goals
- Make the marketing flag test assert the public inactive-resolution behavior instead of a private sparse-map representation.
- Remove the form-engine ESM/CommonJS cycle without changing form visibility, show-rule evaluation, save payload, or mock detail behavior.
- Preserve the project's existing CommonJS API/adapters and avoid a repository-wide module-type switch.
- Verify the original failures and expose any later independent test failures accurately.
## Non-goals
- Do not add `"type": "module"` to the root package because many existing `.js` API, config, fixture, and utility files are CommonJS.
- Do not rewrite all `packageDynamicForm` files to one module system.
- Do not change marketing flag production semantics.
- Do not repair unrelated date-dependent or mini-program-global (`wx`) failures unless they are proven to be part of these module cycles.
## Design
### Marketing flag contract
`buildMarketingFlagMap()` remains a sparse active-only index. The test will assert:
- active goods resolve to `MARKETING_FLAG_ACTIVE`;
- inactive goods are not materialized in the sparse map;
- `resolveMarketingFlag()` returns `0` for that inactive goods ID.
This protects consumer-visible behavior while allowing the internal map to remain compact.
### Form-engine module boundary
The form engine is already predominantly ESM. `group-visibility.js` and the recently added `show-rule-context.js` will follow their ESM callers:
- `group-visibility.js` uses static imports for `evaluateShowRule` and context resolution and exports its two public functions.
- `show-rule-context.js` uses named ESM exports.
- tests that synchronously require ESM form-engine modules use ESM imports instead.
This removes the core ESM -> CommonJS -> ESM cycle while keeping behavior and function signatures unchanged.
### CommonJS mock boundary
After the core cycle is removed, tests may still expose a second re-entry: an ESM test loads `submit-adapter.js` while a CommonJS mock synchronously requires the same adapter during concurrent suite initialization. The repair will be evidence-driven:
- rerun focused tests after the core conversion;
- if the re-entry remains, move the small mock-only transformations behind a CommonJS-safe helper or convert only the affected mock boundary to ESM and update its callers consistently;
- do not duplicate the full submit adapter or introduce a package-wide module declaration.
## Verification
- `node --test tests/marketingFlag.test.mjs`
- focused show-rule and form-engine tests
- focused mock/detail tests if the second cycle reproduces
- `npm run test:dynamicForm`
- `npm test`
Any later independent failure will be reported separately instead of being attributed to this repair.
/** 行内子字段显隐 childrenShowRules(对齐 gl_tape EditForm.itemShow) */ /** 行内子字段显隐 childrenShowRules(对齐 gl_tape EditForm.itemShow) */
const { evaluateShowRule } = require('./group-show-rule-eval.js') import { evaluateShowRule } from './group-show-rule-eval.js'
const { resolveShowRuleContextValue } = require('./show-rule-context.js') import { resolveShowRuleContextValue } from './show-rule-context.js'
function getRowFieldValue(rowFields = [], key = '', rowMap = null) { function getRowFieldValue(rowFields = [], key = '', rowMap = null) {
const field = (rowFields || []).find(item => item.key === key) const field = (rowFields || []).find(item => item.key === key)
...@@ -55,7 +55,4 @@ function filterVisibleRowFields(group = {}, rowFields = [], rowMap = null, pageC ...@@ -55,7 +55,4 @@ function filterVisibleRowFields(group = {}, rowFields = [], rowMap = null, pageC
) )
} }
module.exports = { export { isGroupChildVisibleInRow, filterVisibleRowFields }
isGroupChildVisibleInRow,
filterVisibleRowFields
}
...@@ -9,7 +9,7 @@ function normalizeContextArray(values) { ...@@ -9,7 +9,7 @@ function normalizeContextArray(values) {
)] )]
} }
function resolveShowRuleSceneCodes(pageContext = {}) { export function resolveShowRuleSceneCodes(pageContext = {}) {
const sceneCodes = normalizeContextArray( const sceneCodes = normalizeContextArray(
(pageContext.sceneList || []).map(item => item?.baseSceneCode) (pageContext.sceneList || []).map(item => item?.baseSceneCode)
) )
...@@ -19,11 +19,11 @@ function resolveShowRuleSceneCodes(pageContext = {}) { ...@@ -19,11 +19,11 @@ function resolveShowRuleSceneCodes(pageContext = {}) {
return normalizeContextArray(pageContext.baseSceneCode) return normalizeContextArray(pageContext.baseSceneCode)
} }
function resolveShowRuleBrandIds(pageContext = {}) { export function resolveShowRuleBrandIds(pageContext = {}) {
return normalizeContextArray(pageContext.brandIds || []) return normalizeContextArray(pageContext.brandIds || [])
} }
function resolveShowRuleContextValue(key = '', pageContext = {}) { export function resolveShowRuleContextValue(key = '', pageContext = {}) {
if (key === '$sceneCodes') { if (key === '$sceneCodes') {
const sceneCodes = resolveShowRuleSceneCodes(pageContext) const sceneCodes = resolveShowRuleSceneCodes(pageContext)
return sceneCodes.length ? sceneCodes : null return sceneCodes.length ? sceneCodes : null
...@@ -34,9 +34,3 @@ function resolveShowRuleContextValue(key = '', pageContext = {}) { ...@@ -34,9 +34,3 @@ function resolveShowRuleContextValue(key = '', pageContext = {}) {
} }
return undefined return undefined
} }
module.exports = {
resolveShowRuleSceneCodes,
resolveShowRuleBrandIds,
resolveShowRuleContextValue
}
import { describe, it } from 'node:test' import { describe, it } from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs' import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { evaluateAppShowRuleExpression } from '../form-engine/app-subform-json.js' import { evaluateAppShowRuleExpression } from '../form-engine/app-subform-json.js'
import { fallbackEvaluate } from '../form-engine/group-show-rule-eval.js'
const require = createRequire(import.meta.url)
const { fallbackEvaluate } = require('../form-engine/group-show-rule-eval.js')
const schema = JSON.parse(readFileSync( const schema = JSON.parse(readFileSync(
new URL('../fixtures/schema-store-daily-v2.3.0.json', import.meta.url), new URL('../fixtures/schema-store-daily-v2.3.0.json', import.meta.url),
......
...@@ -1711,7 +1711,7 @@ describe('negotiation schema (F3)', async () => { ...@@ -1711,7 +1711,7 @@ describe('negotiation schema (F3)', async () => {
const { normalizeSchemaRoot } = await import('../form-engine/schema-normalizer.js') const { normalizeSchemaRoot } = await import('../form-engine/schema-normalizer.js')
const { createRequire } = await import('node:module') const { createRequire } = await import('node:module')
const require = createRequire(import.meta.url) const require = createRequire(import.meta.url)
const { filterVisibleRowFields } = require('../form-engine/group-visibility.js') const { filterVisibleRowFields } = await import('../form-engine/group-visibility.js')
const negotiationSchema = loadSchemaFixture('negotiation') const negotiationSchema = loadSchemaFixture('negotiation')
const { SCHEMA_OPTIONS_MAP } = require('../fixtures/mock-meta.js') const { SCHEMA_OPTIONS_MAP } = require('../fixtures/mock-meta.js')
......
import { describe, it } from 'node:test' import { describe, it } from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { createRequire } from 'node:module' import { fallbackEvaluate } from '../form-engine/group-show-rule-eval.js'
const require = createRequire(import.meta.url)
const { fallbackEvaluate } = require('../form-engine/group-show-rule-eval.js')
describe('group-show-rule-eval fallback', () => { describe('group-show-rule-eval fallback', () => {
it('IT-SHOW-RULE-FB-001: fallback matches F3 expressions', () => { it('IT-SHOW-RULE-FB-001: fallback matches F3 expressions', () => {
......
import { describe, it } from 'node:test' import { describe, it } from 'node:test'
import assert from 'node:assert/strict' import assert from 'node:assert/strict'
import { createRequire } from 'node:module' import { evaluateShowRule } from '../form-engine/group-show-rule-eval.js'
const requireMod = createRequire(import.meta.url)
describe('group-show-rule-eval', () => { describe('group-show-rule-eval', () => {
const { evaluateShowRule } = requireMod(
'../form-engine/group-show-rule-eval.js'
)
function getRowFieldValue(rowFields, key) { function getRowFieldValue(rowFields, key) {
const field = rowFields.find(item => item.key === key) const field = rowFields.find(item => item.key === key)
if (!field) return null if (!field) return null
......
...@@ -13,13 +13,14 @@ const { ...@@ -13,13 +13,14 @@ const {
} = await import('../utils/marketingFlag.js') } = await import('../utils/marketingFlag.js')
describe('marketingFlag', () => { describe('marketingFlag', () => {
it('buildMarketingFlagMap maps single goods by merchantGoodsId', () => { it('buildMarketingFlagMap indexes active goods and resolves inactive goods to zero', () => {
const map = buildMarketingFlagMap([ const map = buildMarketingFlagMap([
{ goodsFlag: 1, marketingFlag: 1, goods: { merchantGoodsId: 100 } }, { goodsFlag: 1, marketingFlag: 1, goods: { merchantGoodsId: 100 } },
{ goodsFlag: 1, marketingFlag: 0, goods: { merchantGoodsId: 200 } } { goodsFlag: 1, marketingFlag: 0, goods: { merchantGoodsId: 200 } }
]) ])
assert.equal(map['100'], MARKETING_FLAG_ACTIVE) assert.equal(map['100'], MARKETING_FLAG_ACTIVE)
assert.equal(map['200'], 0) assert.equal(map['200'], undefined)
assert.equal(resolveMarketingFlag(map, { merchantGoodsId: 200 }), 0)
}) })
it('resolveMarketingFlag returns active only when mapped', () => { it('resolveMarketingFlag returns active only when mapped', () => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!