Skip to content

fix: stop regression sanitizer from corrupting the Categories Applies column - #51

Closed
luandro wants to merge 4 commits into
mainfrom
chore/geometry-cleanup-and-regression-sanitizer-fix
Closed

luandro wants to merge 4 commits into
mainfrom
chore/geometry-cleanup-and-regression-sanitizer-fix

Conversation

@luandro

@luandro luandro commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes a bug where the regression-test sanitizer corrupted the Categories sheet's Applies column, plus removes dead code surfaced while scoping #17.

The bug

sanitizeRowData (src/regressionTesting.ts) hardcoded index 3 as "Color" and overwrote it with #0066CC. In the current six-column Categories layout (Name, Icon, Fields, Applies, Category ID, Icon ID) index 3 is the Applies column, so every sanitized category lost its observation/track value. The builder silently coerced the invalid value to ["observation"], no category retained track, and generation failed with the track-coverage error.

The fix

  • sanitizeRowData is now header-aware: it resolves columns by header label (with canonical fallbacks), preserves Applies, sets a deterministic test-category-N Category ID, clears Icon ID, and only writes a test color into an explicit Color column.
  • Handles both the canonical layout and the import layout (Name, Icon, Fields, ID, Color, Icon ID from importService.ts), and scrubs numeric Category IDs (not just strings).

Dead code removed (from #17 scoping)

  • VALID_GEOMETRY_TYPES (src/validation.ts) — zero references.
  • src/generateConfig/processPresets.ts + its orphan src/test/testRow2Translation.ts — the v2 pipeline builds categories via builders/payloadBuilder.ts (buildCategories); processPresets was only referenced by that one unregistered test.
  • Corrected the stale CategoryRow column comment in src/types.ts (claimed [3]=Color / [4]=Geometry).

Note: #17's actual feature (per-category appliesTo via the Applies column) is already implemented across export/import/lint/docs — this PR is the cleanup + a real bug found during that scoping. #17 can be closed as completed.

Test

Adds testRegressionTesting.ts (10 cases), registered as Suite 15 and runTestSuite("regression"). Updates the test README and AGENTS.md pipeline note.

Verification

  • bunx tsc --noEmit — clean
  • bunx biome check — clean
  • Sanitizer logic unit-checked against the actual function: 15/15 assertions (canonical row, legacy 4-col Color, reordered headers, numeric ID, import layout, degenerate 1-col grid)
  • Adversarially reviewed (verify → plan → review → fix → re-review): ship

Scope

Only the files for this change are included. Unrelated in-progress edits (payloadBuilder.ts, utils.ts, version.ts, lint/*, testUtilsSlugify.ts) are not part of this PR.

Remaining (needs Apps Script environment)

Push to the test project and run runAllTests() / runTestSuite("regression"), do a manual regression-copy from a canonical 6-column sheet, and round-trip a generated .comapeocat.

Greptile Summary

This PR fixes the regression spreadsheet sanitizer and removes unused legacy preset code. The main changes are:

  • Header-aware Categories row sanitization that preserves Applies.
  • Deterministic scrubbing for Category ID, Icon ID, icon URLs, and explicit Color columns.
  • New regression sanitizer tests registered under Suite 15 and runTestSuite("regression").
  • Removal of unused processPresets, testRow2Translation, and VALID_GEOMETRY_TYPES.

Confidence Score: 5/5

Safe to merge; no blocking issues found.

The sanitizer change is narrow and matches the current builder and import layouts. Tests cover the original Applies corruption case plus reordered headers, legacy color layout, import layout, and numeric IDs. Removed code was tied to an orphan legacy test path.

No files require special attention.

T-Rex T-Rex Logs

What T-Rex did

  • Ran a TypeScript sanity check with noEmit and it completed successfully.
  • Ran the Biome check for sanitizer validation and it completed successfully.
  • Re-ran the sanitizer harness and all six assertions passed, including Applies preservation and import/reordered header behavior.
  • Tried Apps Script deployment via clasp, but deployment was blocked because clasp was not found (EXIT_CODE: 1).

View all artifacts

T-Rex Ran code and verified through T-Rex

Important Files Changed

Filename Overview
src/regressionTesting.ts Categories sanitization now resolves columns from headers, preserves Applies, scrubs category/icon IDs, and only changes explicit color columns.
src/test/testRegressionTesting.ts New Apps Script regression tests cover canonical, reordered, legacy, import-layout, and numeric-ID sanitizer cases.
src/test/testRunner.ts Registers the regression sanitizer suite in runAllTests and runTestSuite("regression").
src/generateConfig/processPresets.ts Deleted unused legacy preset-processing helper that was only referenced by the removed orphan test.
src/test/testRow2Translation.ts Removed orphan row-2 translation diagnostic test tied to the deleted legacy preset path.
tsconfig.json Test exclusion list swaps the removed row-2 translation test for the new regression sanitizer test.

Sequence Diagram

sequenceDiagram
participant Source as Production sheet
participant Copy as sanitizeAndCopySheetData
participant Sanitize as sanitizeRowData
participant Target as Test sheet

Source->>Copy: Read sheet values
Copy->>Copy: Preserve header row
Copy->>Sanitize: Pass data row and header
Sanitize->>Sanitize: Resolve Categories columns by header label
Sanitize->>Sanitize: Preserve Applies and scrub IDs
Sanitize-->>Copy: Return sanitized same-width row
Copy->>Target: Write sanitized grid
Loading

Reviews (6): Last reviewed commit: "fix: make findCol resolve duplicate head..." | Re-trigger Greptile

… column

The regression-test sanitizer hardcoded index 3 as "Color" and overwrote it with "#0066CC". In the current six-column Categories layout (Name, Icon, Fields, Applies, Category ID, Icon ID) index 3 is the Applies column, so every sanitized category lost its observation/track value and generation failed with a track-coverage error.

- Make sanitizeRowData header-aware: resolve columns by header label with canonical fallbacks, preserve Applies, set a deterministic Category ID, clear Icon ID, and only write a test color into an explicit Color column. Handles both the canonical layout and the import layout (Name, Icon, Fields, ID, Color, Icon ID), and scrubs numeric Category IDs.

Also removes dead code surfaced while scoping #17: unused VALID_GEOMETRY_TYPES (validation.ts); processPresets.ts and its orphan testRow2Translation.ts (the v2 pipeline builds categories via builders/payloadBuilder.ts buildCategories); and corrects the stale CategoryRow column comment in types.ts.

Adds testRegressionTesting.ts (Suite 15 / runTestSuite("regression")) and updates AGENTS.md + the test README. Verified: tsc --noEmit and biome clean; sanitizer logic unit-checked 15/15.
luandro added 3 commits July 23, 2026 06:49
- regressionTesting.ts sanitizeRowData: every other resolved column
  (nameCol, iconCol, categoryIdCol, iconIdCol) is guarded with
  `< sanitized.length` before array access, but fieldsCol wasn't. The
  out-of-bounds read was harmless (returns undefined, && short-circuits)
  but inconsistent, and would silently no-op instead of failing loudly
  if fieldsCol ever resolved past the row's actual width.
- types.ts CategoryRow: the JSDoc documents [5] = Icon ID, but the
  interface stopped at [4], so row[5] fell back to the untyped
  string | number | boolean array element type with no autocomplete
  or narrowing.

Reported by greptile CLI review of PR #51.
findCol (new in this PR) used Array.findIndex, resolving to the FIRST
matching header on a sheet with duplicate column names. The codebase's
other column-resolution helper, getCol (three instances in
payloadBuilder.ts), builds a headerMap via forEach where a later
duplicate key overwrites an earlier one — so it resolves to the LAST
match instead. Scan the full header and keep the last match, matching
getCol's behavior.

Only matters on a degenerate sheet with duplicate column names (not
exercised by the existing 10-case test suite, and nothing else in the
codebase guards against duplicate headers either), so this is a
consistency fix, not a functional bug fix.

Flagged by pr-critical-reviewer as a non-blocking inconsistency during
final PR readiness review. Implemented with mimo CLI
(togetherai/Qwen3.7-Max), reviewed and verified (tsc, biome, manual
diff read) before committing.
@luandro

luandro commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded: the sanitizer bug this PR fixes (Applies column clobbered by the regression-test color) is fixed on main by the #61 canonical-layout work (06799ca) plus the header-guarded sanitizer from the post-merge review (297fe40). This PR's header-aware column resolution would now conflict with the merged index-based fix. Valuable analysis — the header-aware idea informed the review. Follow-up for its author: run the regression suite inside Apps Script.

luandro added a commit that referenced this pull request Oct 19, 2026
…, keep Color (#61)

Import now writes the same Categories layout generate reads:
Name | Icon | Fields | Applies | Category ID | Color | Icon ID.

- Add CATEGORY_HEADERS single-source constant in src/constants/columns.ts;
  CATEGORY_COL gains COLOR (5), ICON_ID moves 5 -> 6.
- populateCategoriesSheet (.comapeocat import) writes appliesTo per category
  (default "track, observation" only when the config lacks the field, logged),
  Category ID at E, Color at F, Icon ID at G; keeps column-A backgrounds.
- applyCategories (legacy mapeosettings import) writes the same canonical
  header and per-preset appliesTo/id/color/iconId values.
- apiService: EXPECTED_HEADERS.CATEGORIES, the legacy-A1 header rewrite, and
  validateCategoriesHeaderLayout now derive from CATEGORY_HEADERS (getter
  avoids GAS alphabetical load-order boot failure).
- lint: validateCategoryIcons resolves the Icon ID column by header;
  new Task 7 rule flags old import layout (ID/Color at D/E, no Applies).
- regressionTesting sanitizer and CategoryRow doc comment match canonical
  columns (fixes stale index-3-as-Color assumption, see #51).
- Tests: new src/scripts/check-import-layout.cjs (npm run test:import-layout)
  covers both import writers, generate->import->generate round trip with
  byte-identical appliesTo + color, and layout validation; new
  testCanonicalCategoriesLayoutRoundTrip in src/test/testBuildAndImport.ts.
  gasSimHarness FakeSheet gains background/color + autoResizeColumns support.
- Docs: categories-sheet reference/how-to and linting-rules updated.

Closes #52.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@luandro luandro closed this Oct 19, 2026
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.

1 participant