Skip to content

refactor: align @stdlib/array outliers with namespace majority patterns#11771

Closed
Planeshifter wants to merge 0 commit into
developfrom
philipp/drift-array-2026-04-25
Closed

refactor: align @stdlib/array outliers with namespace majority patterns#11771
Planeshifter wants to merge 0 commit into
developfrom
philipp/drift-array-2026-04-25

Conversation

@Planeshifter

@Planeshifter Planeshifter commented Apr 25, 2026

Copy link
Copy Markdown
Member

Description

Aligning outliers in @stdlib/array with namespace majority patterns (random namespace pick, seed 20260425).

Namespace summary

  • Member count: 102 direct child packages of @stdlib/array, none autogenerated.
  • Features analyzed: file-tree presence, package.json shape (top keys, scripts, directories, main), README section structure, manifest.json shape, error-construction style, JSDoc shape.
  • Features with clear majority (≥75%):
    • Error-construction style — 44 of 54 throwing packages (≈81%) construct ALL error messages via @stdlib/string/format. The remaining 10 mix plain-string throws with format()-wrapped throws in the same lib/main.js.
    • package.json main field — 101 of 102 (99%) use "./lib". One outlier uses "lib/index.js".
  • Features without clear majority (excluded from drift detection): nothing else reached the 75% threshold across this heterogeneous composite namespace. README H2 sequence has two roughly equal canonical orderings (Usage / Notes / Examples / See Also at 45%, Usage / Examples / See Also at 38%), neither dominant. Several files (docs/types/index.d.ts, docs/repl.txt) are missing in a coherent endian/struct sub-family with no mechanical fix that doesn't introduce TODO stubs, so they are logged for human review rather than corrected here.

Per-outlier corrections

Each outlier ships as a single commit. Wrapping a static-string throw in format( ... ) is identity on the message text (format with no extra args returns the literal unchanged), so behavior is preserved.

array/fixed-endian-factory

lib/main.js had 5 plain-string throws alongside 51 format()-wrapped throws (~91% conformance). Plain throws were two this-context guards, two empty-array reduce guards, and one storage-bounds RangeError. All 5 are now wrapped; file is at 100%.

array/incrspace

lib/main.js had 1 plain-string throw alongside 3 format()-wrapped throws (~75% conformance). The single outlier was a static RangeError on max-array-length. Wrapping it brings the file to 100%.

array/little-endian-factory

lib/main.js had 2 plain-string throws alongside 5 format()-wrapped throws (~71% conformance). Both plain throws were this-context guards. Wrapping them brings the file to 100%.

array/struct-factory

lib/main.js had 1 plain-string throw alongside 21 format()-wrapped throws (~95% conformance). The single outlier was a static RangeError on storage bounds. Wrapping it brings the file to 100%.

array/base

package.json main field set to "lib/index.js"; 101 of 102 sibling packages (99%) use "./lib". Node resolves both identically since lib/index.js exists, so this is a purely stylistic alignment with no behavioral effect.

Dropped from this PR (logged in the local report)

Six additional outliers were corrected in initial commits but rolled back before this update because their files (or their downstream consumers) carry pre-existing CI failures unrelated to the drift correction:

  • array/bool (39 plain throws) — lib/main.js triggers pre-existing max-lines and FIXME/TODO lint warnings on origin/develop.
  • array/complex64 (41) — pre-existing JSDoc-spacing lint error at lib/main.js:2891 and pre-existing assertion failure in test/test.at.js (returns expected imaginary component for index -10).
  • array/complex128 (41) — same pre-existing test/test.at.js failure as complex64.
  • array/index (8) — drift fix is clean locally, but array/to-fancy (its main downstream consumer) has multiple pre-existing test failures that reproduce against unmodified develop and trip Run affected tests.
  • array/filled (2) — array/to-fancy/benchmark/benchmark.get.js requires @stdlib/array/filled, which makes to-fancy an "affected" dependent of any filled change. Same pre-existing to-fancy test failures as above.
  • array/filled-by (6) — has 1000+ downstream consumers; sampling indicates the same kind of pre-existing-failure noise is likely. Dropped to keep this PR's CI green.

The drift in all six is real and the wrap diffs are reproducible. They should be re-applied in a subsequent PR alongside the pre-existing fixes once those are addressed.

Questions

No.

Other

Validation

  • Structural feature extraction (file presence, README headings, package.json and manifest.json shape) over all 102 members.
  • Semantic feature extraction (error-construction patterns, JSDoc shape, signature) by regex over each lib/main.js.
  • Three-agent drift validation in parallel: opus semantic-review (intent vs. drift), opus cross-reference (test/example coupling and external consumers), sonnet structural-review (majority pattern applicability per package).
  • For the error-construction outliers: all received confirmed-drift from the semantic and structural agents and ok-to-fix from the cross-reference agent.
  • For array/base.main: cross-reference agent confirmed no consumer references the literal "lib/index.js" value; structural agent confirmed "./lib" resolves identically.
  • Tests use t.throws( fn, TypeError, '' ), which checks the error class only; the third argument is a tape display label, not a message expectation. No outlier's tests, examples, or external consumers couple to the literal error-construction shape.
  • For each retained package, the modified lib/main.js was syntax-checked (node -c), the package's tape suite ran clean locally, and the (small) set of downstream consumer tests was sampled clean as well.

Deliberately excluded

  • Features without a clear ≥75% majority across the namespace.
  • The 17 packages missing ## See Also README sections — adding meaningful related-package links requires per-package editorial judgment about which siblings are related and is out of scope for a mechanical drift correction.
  • The docs/types/* and docs/repl.txt gaps in the endian/struct sub-family (fixed-endian-factory, fixed-endian-float32, fixed-endian-float64, little-endian-factory, little-endian-float32, little-endian-float64, struct-factory) are real but require hand-written TypeScript declarations rather than boilerplate; logged in the local report for separate human follow-up.
  • The 7 packages with package.json.directories missing the doc key — they also have no docs/ folder, so adding the field without the directory would create a stale reference.
  • Polyfill throw new Error( 'not implemented' ) calls in 12 lib/polyfill.js files (e.g. array/buffer/lib/polyfill.js) were not normalized: polyfills are coherent with each other and represent a distinct family from the format()-using majority.
  • The array/base directories.benchmark omission — the package has no benchmark/ folder, so adding the field would be a stale reference.
  • The six packages listed under "Dropped from this PR" above.

The full local report (feature-by-feature majority distribution, per-outlier drift findings, drops with reasons, and decisions) is saved at ~/drift-reports/drift-array-2026-04-25.md.

Checklist

AI Assistance

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

This PR was authored entirely by Claude Code, running the cross-package API drift detection routine. The routine: (1) randomly selected the @stdlib/array namespace from the 120 namespaces with ≥8 non-autogenerated direct child packages (seed 20260425); (2) extracted structural features (file tree, package.json shape, README headings) and semantic features (error-construction patterns, JSDoc shape) across all 102 members; (3) identified format()-wrapped throws as the namespace majority pattern at ~81% conformance among throwing packages, and "./lib" as the main-field majority at 99% conformance; (4) flagged outliers; (5) validated each via three parallel agents (opus semantic-review, opus cross-reference, sonnet structural-review); (6) applied each surviving correction as one commit per package; (7) dropped six error-construction commits before publishing because those packages either had pre-existing failures in their own files (bool, complex64, complex128) or triggered pre-existing failures in their downstream consumers via Run affected tests (index, filled, filled-by). Message text is preserved verbatim across all retained commits; no test or example expectations changed.


@stdlib-js/reviewers

@stdlib-bot

stdlib-bot commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
array/base $\color{red}39190/51974$
$\color{green}+75.40%$
$\color{red}585/589$
$\color{green}+99.32%$
$\color{red}2/528$
$\color{green}+0.38%$
$\color{red}39190/51974$
$\color{green}+75.40%$
array/fixed-endian-factory $\color{red}1184/1437$
$\color{green}+0.00%$
$\color{red}155/168$
$\color{green}+0.00%$
$\color{red}23/33$
$\color{green}+0.00%$
$\color{red}1184/1437$
$\color{green}+0.00%$
array/incrspace $\color{green}116/116$
$\color{green}+0.00%$
$\color{green}16/16$
$\color{green}+0.00%$
$\color{green}1/1$
$\color{green}+0.00%$
$\color{green}116/116$
$\color{green}+0.00%$
array/little-endian-factory $\color{red}334/566$
$\color{green}+0.00%$
$\color{green}4/4$
$\color{green}+0.00%$
$\color{red}0/4$
$\color{green}+0.00%$
$\color{red}334/566$
$\color{green}+0.00%$
array/struct-factory $\color{red}328/829$
$\color{green}+0.00%$
$\color{green}4/4$
$\color{green}+0.00%$
$\color{red}0/3$
$\color{green}+0.00%$
$\color{red}328/829$
$\color{green}+0.00%$

The above coverage report was generated for the changes in this PR.

@Planeshifter Planeshifter force-pushed the philipp/drift-array-2026-04-25 branch 3 times, most recently from 24c731e to b14046a Compare April 25, 2026 09:31
@Planeshifter Planeshifter changed the title refactor: align @stdlib/array outliers with namespace error-construction majority refactor: align @stdlib/array outliers with namespace majority patterns Apr 25, 2026
@github-actions github-actions Bot mentioned this pull request Apr 25, 2026
N = value.length;
if ( idx+N > this._length ) {
throw new RangeError( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' );
throw new RangeError( format( 'invalid arguments. Target array lacks sufficient storage to accommodate source values.' ) );

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is getting interpolation here and elsewhere; revert these changes

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged. You're right — for static messages with no interpolation, plain string literals are the correct stdlib style; the format() wrap was a misread of the namespace majority by the drift detection routine. Reverted all four commits and resetting the branch to develop. Closing the PR.


Generated by Claude Code

@Planeshifter Planeshifter force-pushed the philipp/drift-array-2026-04-25 branch from 0af997c to 5a06940 Compare April 25, 2026 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants