fix(workflows): satisfy noUncheckedIndexedAccess in selection math - #2545
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packages/workflows/builtin/selection-math.tsships as raw TypeScript inside@bastani/atomic, so consumers typecheck it directly. UndernoUncheckedIndexedAccess, the four indexed compound assignments inaccumulatearenumber | undefined, and a consumertsc --noEmitfails with fourTS2532errors at lines 130–133.This adds the non-null assertions the rest of the file already uses, and locks the regression in the SDK type verifier.
Fixes #2543.
Changes
packages/workflows/builtin/selection-math.ts—w[a]! += p; c[a]! += 1; w[b]! += 1 - p; c[b]! += 1;. No behavior change:aandbare candidate indices the caller sizedw/cfor, whichtest/unit/selection-math.test.tsasserts. The style matchesmean_preferencein the same file, which already used!.packages/coding-agent/scripts/verify-workflow-sdk-types.ts— newexpect: "pass"variantauto-include-no-unchecked-indexed-access, with tsconfig extras{ noUncheckedIndexedAccess: true, allowImportingTsExtensions: true }, reusing the existingauto-include-via-atomic-importconsumer files. Importing@bastani/atomicpulls ambient → every builtin → tournament → selection-math, so the variant exercises the real consumer path.packages/workflows/CHANGELOG.md— one### Fixedentry under## [Unreleased]. No released section touched.Diff is 3 files, +19 −4.
Verification
tsconselection-math.ts(--strict --noUncheckedIndexedAccess --allowImportingTsExtensions --module NodeNext --moduleResolution NodeNext --skipLibCheck --ignoreConfig)(130,3) (131,3) (132,3) (133,3) error TS2532, exit 1. After: no output, exit 0TS2532resolving insidenode_modules/@bastani/atomic/dist/.../selection-math.ts(130–133), i.e. the consumer bug end-to-end. Passes afterbun run verify:workflow-types(frompackages/coding-agent)npm run test:unit -- test/unit/selection-math.test.tsnpm run checkTwo notes on how those commands had to be run
Both are properties of this checkout, not of the fix.
--ignoreConfig. The repo pinstypescript@7.0.2, which raisesTS5112: tsconfig.json is present but will not be loaded if files are specified on commandlinebefore any type checking. That error fires identically with and without the fix, so it cannot distinguish the two states.--ignoreConfigis TypeScript's own suggested remedy and leaves every other flag intact.verify:workflow-typescannot run on a versionless base unaided. On a clean tree it fails at the first variant withNo version matching "0.0.0" found for specifier "@bastani/atomic-natives"— the versionless-release-base design inAGENTS.md, pre-existing and unrelated to this issue. It was made runnable by temporarily stamping the published0.9.14-alpha.5withscripts/bump-version.ts, running the verifier, then restoring the0.0.0placeholder (confirmed:"version": "0.0.0", natives pin0.0.0, emptygit status).Known limitation (not addressed here)
All three reviewers independently raised the same non-blocking point, classified beyond this issue's scope: the new variant is the only guard against this class of consumer-facing type break, but nothing runs it automatically.
verify:workflow-typesis referenced only by its own definition inpackages/coding-agent/package.json— no CI job and no prek hook invokes it. Wiring it up (and giving it an escape hatch for versionless bases) is worth a follow-up issue.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Greptile Summary
This change makes the raw workflow selection helper compatible with consumer projects that enable
noUncheckedIndexedAccess, adds a matching SDK type-check fixture, and documents the fix. The potential consumer type-check failure was disproved by comparing the preceding revision and this revision under identical strict compiler settings: the earlier code produced four TS2532 indexed-accumulator errors, while the updated code completed successfully. The focused selection-math test suite also passed all 9 tests.Confidence Score: 5/5
Safe to merge: the strict consumer compilation path now succeeds and focused selection-math behavior remains passing.
No remaining defects were evidenced. The affected type-checking path was exercised before and after the fix, reproducing the prior compiler failure and confirming that the updated implementation resolves it.
Files Needing Attention: No files need further attention;
packages/workflows/builtin/selection-math.tsreceived direct strict-compilation and focused test coverage.What T-Rex did
Reviews (1): Last reviewed commit: "fix(workflows): satisfy noUncheckedIndex..." | Re-trigger Greptile