A small module prepares an account signature for the profile panel. After a recent PR, the review noticed that some input values started being accepted too broadly, and repeated reads sometimes behave unpredictably after external changes to the result.
loadAccountChip function accepts a string accountId and an asynchronous fetchAccount source.null.AccountChip contract.flags field in a successful result must be an array of strings.accountId may use a cache.src/accountChip.ts.node --input-type=module -e "import('./src/accountChip.ts').then(async ({ loadAccountChip }) => { const calls = []; const result = await loadAccountChip(' ', async (id) => { calls.push(id); return { id, label: 'A', flags: ['ok'] }; }); console.log(JSON.stringify({ result, calls })); })"
flags composition:node --input-type=module -e "import('./src/accountChip.ts').then(async ({ loadAccountChip, resetAccountChipCache }) => { resetAccountChipCache(); const result = await loadAccountChip('acct-7', async () => ({ id: 'acct-7', label: 'VIP', flags: ['ok', 42] })); console.log(JSON.stringify(result)); })"
node --input-type=module -e "import('./src/accountChip.ts').then(async ({ loadAccountChip, resetAccountChipCache }) => { resetAccountChipCache(); const first = await loadAccountChip('acct-9', async () => ({ id: 'acct-9', label: 'Core', flags: ['new'] })); if (first) first.flags.push('mutated'); const second = await loadAccountChip('acct-9', async () => ({ id: 'acct-9', label: 'Core', flags: ['new'] })); console.log(JSON.stringify({ first, second })); })"
accountId, the function returns null and does not call fetchAccount.flags containing at least one non-string value is considered invalid and yields null.flags on an already returned object, a subsequent read of the same account must not receive this external mutation from the cache.strict: truenode --input-type=moduleUse line comments to explain the problem, its impact, the fix and how to test it.