From 1041c360200137f1dc5c13eb3ce89229b27459e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Lucas?= Date: Thu, 12 Nov 2026 08:09:22 +0100 Subject: [PATCH 1/2] fix(core): reject a tower step that misses the top tier (ADR-0013) --- ...ower-end-temperature-is-reached-exactly.md | 22 +++++++++++++++++++ packages/core/src/tower-config.test.ts | 18 ++++++++++++++- packages/core/src/tower-config.ts | 12 ++++++++++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 docs/adr/0013-tower-end-temperature-is-reached-exactly.md diff --git a/docs/adr/0013-tower-end-temperature-is-reached-exactly.md b/docs/adr/0013-tower-end-temperature-is-reached-exactly.md new file mode 100644 index 0000000..61c9058 --- /dev/null +++ b/docs/adr/0013-tower-end-temperature-is-reached-exactly.md @@ -0,0 +1,22 @@ +# 0013. The end temperature is reached exactly + +**Status:** accepted; amends ADR-0005 (tower config) + +## Context +`tierCount` floors `|end - start| / step` (RPT-004). Two configs passed validation and printed something other than what the form and the STL name say: + +- A step larger than the range, such as 230 to 228 step 5, gives one tier and no temperature change. +- A step that does not divide the range, such as 230 to 190 step 15, prints 230, 215 and 200 °C. The form calls the end field "Top tier" and the STL name encodes `230to190`, but no tier prints at 190 °C. + +Two readings are possible: the end temperature is the top tier, or it is only a bound. As a bound, the form label, the STL name (ADR-0005), the output header and the report would all have to show a derived top temperature instead of the one the user typed. + +## Decision +- The end temperature is the top tier and is reached exactly. +- `validateTowerConfig` rejects a config with fewer than 2 tiers, and a step that does not divide `|end - start|`. The message names the nearest end temperatures that the step does reach. +- The config form shows the same problems, because it already lists `validateTowerConfig` problems. +- The tier formulas (`tierCount`, `tierTemperature`, `tierBoundaryZ`) are unchanged. + +## Consequences +- Every material preset uses step 5 over a range of 30 or 40 °C, so all presets stay valid. +- An STL name or G-code header from an earlier version with a non-dividing step no longer validates after recovery. The user sees the problem in the form and fixes the step or the end temperature. +- Ruled out: treating the end temperature as a bound, which would make the STL name and the "Top tier" label wrong. diff --git a/packages/core/src/tower-config.test.ts b/packages/core/src/tower-config.test.ts index 4a155a5..d670df1 100644 --- a/packages/core/src/tower-config.test.ts +++ b/packages/core/src/tower-config.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { Material, temperaturesOutsidePreset, tierBoundaryZ, tierCount, tierStartZ, tierTemperatures, towerHeight, validateTowerConfig, type TowerConfig } from './tower-config.ts' +import { MATERIAL_PRESETS, Material, temperaturesOutsidePreset, tierBoundaryZ, tierCount, tierStartZ, tierTemperatures, towerHeight, validateTowerConfig, type TowerConfig } from './tower-config.ts' const pla: TowerConfig = { material: Material.PLA, @@ -48,4 +48,20 @@ describe('tower config', () => { expect(validateTowerConfig({ ...pla, blockHeight: 3 })).toContain('block height must be at least 6 mm') expect(validateTowerConfig({ ...pla, step: 1 })).toContain('at most 20 tiers') }) + + it('rejects a step that leaves one tier or misses the top tier (ADR-0013)', () => { + expect(validateTowerConfig({ ...pla, startTemperature: 230, endTemperature: 228, step: 5 })).toEqual([ + 'step 5 °C is larger than the 2 °C range, so the tower would have 1 tier; use at least 2 tiers', + ]) + expect(validateTowerConfig({ ...pla, startTemperature: 230, endTemperature: 190, step: 15 })).toEqual([ + 'step 15 °C does not reach the top tier 190 °C; use 200 or 185 °C, or another step', + ]) + expect(validateTowerConfig({ ...pla, startTemperature: 190, endTemperature: 230, step: 15 })).toEqual([ + 'step 15 °C does not reach the top tier 230 °C; use 220 or 235 °C, or another step', + ]) + }) + + it('keeps every material preset valid', () => { + for (const preset of MATERIAL_PRESETS) expect(validateTowerConfig(preset.config), preset.label).toEqual([]) + }) }) diff --git a/packages/core/src/tower-config.ts b/packages/core/src/tower-config.ts index 2790dbc..010bf1f 100644 --- a/packages/core/src/tower-config.ts +++ b/packages/core/src/tower-config.ts @@ -253,6 +253,17 @@ export const PRUSA_MAX_NOZZLE_TEMPERATURE = 290 export const temperaturesAbovePrinterLimit = (config: TowerConfig): readonly number[] => tierTemperatures(config).filter((t) => t > PRUSA_MAX_NOZZLE_TEMPERATURE) +/** The end temperature is the top tier, so the step must reach it exactly in at least one step (ADR-0013). */ +const stepProblems = (config: TowerConfig): readonly string[] => { + const range = Math.abs(config.endTemperature - config.startTemperature) + if (config.step > range) return [`step ${config.step} °C is larger than the ${range} °C range, so the tower would have 1 tier; use at least 2 tiers`] + if (range % config.step === 0) return [] + const direction = config.endTemperature >= config.startTemperature ? 1 : -1 + const reachable = (tiers: number) => config.startTemperature + direction * config.step * tiers + const below = Math.floor(range / config.step) + return [`step ${config.step} °C does not reach the top tier ${config.endTemperature} °C; use ${reachable(below)} or ${reachable(below + 1)} °C, or another step`] +} + export const validateTowerConfig = (config: TowerConfig): readonly string[] => { const problems: string[] = [] const isFinite = (n: number) => Number.isFinite(n) @@ -265,6 +276,7 @@ export const validateTowerConfig = (config: TowerConfig): readonly string[] => { if (config.startTemperature === config.endTemperature) problems.push('start and end temperature must differ') if (!isFinite(config.blockHeight) || config.blockHeight < MIN_BLOCK_HEIGHT) problems.push(`block height must be at least ${MIN_BLOCK_HEIGHT} mm`) if (!isFinite(config.baseHeight) || config.baseHeight < MIN_BASE_HEIGHT) problems.push(`base height must be at least ${MIN_BASE_HEIGHT} mm`) + if (problems.length === 0) problems.push(...stepProblems(config)) if (problems.length === 0 && tierCount(config) > MAX_TIERS) problems.push(`at most ${MAX_TIERS} tiers`) if (!(Object.values(Material) as string[]).includes(config.material)) problems.push('unknown material') return problems From d2ac7db6128fd56a10d5e37ef12036bc72c6d4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Lucas?= Date: Thu, 12 Nov 2026 08:09:29 +0100 Subject: [PATCH 2/2] chore(backlog): complete TSK-011 --- .../TSK-011-fix-tower-config-accepts-a.md | 36 +++++++++++++++++++ .backlog/tasks/index.md | 7 ++-- .../TSK-011-fix-tower-config-accepts-a.md | 32 ----------------- AGENTS.md | 1 + 4 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 .backlog/tasks/complete/TSK-011-fix-tower-config-accepts-a.md delete mode 100644 .backlog/tasks/pending/TSK-011-fix-tower-config-accepts-a.md diff --git a/.backlog/tasks/complete/TSK-011-fix-tower-config-accepts-a.md b/.backlog/tasks/complete/TSK-011-fix-tower-config-accepts-a.md new file mode 100644 index 0000000..4275534 --- /dev/null +++ b/.backlog/tasks/complete/TSK-011-fix-tower-config-accepts-a.md @@ -0,0 +1,36 @@ +--- +id: TSK-011 +title: Fix: Tower config accepts a step that skips the top tier or leaves a single tier +status: complete +priority: P4 +tags: [] +created: 2026-11-02 +source: report/RPT-004 +depends-on: [] +completed: 2026-11-12 +started: 2026-11-12 +--- + +# Fix: Tower config accepts a step that skips the top tier or leaves a single tier + +## Description + +`validateTowerConfig` accepts a step larger than the range (one tier, no temperature change) and a step that does not divide the range (the "Top tier" temperature is never printed). `tierCount` floors the division in `packages/core/src/tower-config.ts:219-220`. Reproduction and observed output are in RPT-004. + +## Acceptance Criteria + +- [x] A new ADR states whether the end temperature must be reached exactly or is a bound, before any code change — evidence: docs/adr/0013-tower-end-temperature-is-reached-exactly.md: end is reached exactly (2026-11-12) +- [x] validateTowerConfig rejects any config with fewer than 2 tiers — evidence: stepProblems rejects step > range (1 tier) (2026-11-12) +- [x] A step that does not divide the range is rejected, or the UI labels and STL name show the real top tier, as the ADR decides — evidence: non-dividing step rejected with the nearest reachable end temperatures (2026-11-12) +- [x] The config form shows the same problem as validation — evidence: config-form lists validateTowerConfig problems, so it shows the same message (2026-11-12) +- [x] A unit test covers 230 to 228 step 5 and 230 to 190 step 15 — evidence: tower-config.test.ts covers 230 to 228 step 5 and 230 to 190 step 15; all presets stay valid (2026-11-12) + +## Notes + +## Learnings + +## Progress Log + +- [2026-11-02] Created +- [2026-11-12] ADR-0013 and stepProblems in validateTowerConfig +- [2026-11-12] Completed \ No newline at end of file diff --git a/.backlog/tasks/index.md b/.backlog/tasks/index.md index 88466f1..36f8855 100644 --- a/.backlog/tasks/index.md +++ b/.backlog/tasks/index.md @@ -4,10 +4,10 @@ | Status | Count | |--------|-------| -| Pending | 6 | +| Pending | 5 | | Active | 0 | | Blocked | 0 | -| Complete | 10 | +| Complete | 11 | ## Active Tasks @@ -21,7 +21,6 @@ _No active tasks._ | TSK-007 | Public launch with counter and physical print gate | P3 | release, community | 2026-10-18 | | TSK-008 | User transforms binary G-code (.bgcode) from Core One and MK4-class printers | P1 | gcode, prusaslicer, onboarding | 2026-10-18 | | TSK-010 | Fix: No warning when Custom tiers fall below the cold-extrusion limit | P4 | | 2026-10-30 | -| TSK-011 | Fix: Tower config accepts a step that skips the top tier or leaves a single tier | P4 | | 2026-11-02 | | TSK-013 | Fix: Plain G-code with non-UTF-8 bytes loses them in the output | P4 | | 2026-11-05 | ## Recently Completed @@ -29,6 +28,7 @@ _No active tasks._ | ID | Title | Completed | |----|-------|-----------| | TSK-009 | Fix: Tier 0 M109 R turns the hotend off on Klipper firmware | 2026-11-12 | +| TSK-011 | Fix: Tower config accepts a step that skips the top tier or leaves a single tier | 2026-11-12 | | TSK-012 | Fix: No CI workflow runs typecheck and tests on pull requests | 2026-11-11 | | TSK-014 | Fix: Binary G-code report status double-counts inserted tier commands | 2026-11-11 | | TSK-015 | Fix: Single-object Klipper or OctoPrint-labelled G-code fails with multiple-objects | 2026-11-11 | @@ -37,4 +37,3 @@ _No active tasks._ | TSK-003 | User downloads a labelled tower STL that matches the config | 2026-10-18 | | TSK-004 | User reviews a change report before download | 2026-10-18 | | TSK-005 | Config is recovered automatically from the uploaded G-code | 2026-10-18 | -| TSK-006 | Correct towers for all common PrusaSlicer profile variants | 2026-10-18 | diff --git a/.backlog/tasks/pending/TSK-011-fix-tower-config-accepts-a.md b/.backlog/tasks/pending/TSK-011-fix-tower-config-accepts-a.md deleted file mode 100644 index 1b4fe39..0000000 --- a/.backlog/tasks/pending/TSK-011-fix-tower-config-accepts-a.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -id: TSK-011 -title: Fix: Tower config accepts a step that skips the top tier or leaves a single tier -status: pending -priority: P4 -tags: [] -created: 2026-11-02 -source: report/RPT-004 -depends-on: [] ---- - -# Fix: Tower config accepts a step that skips the top tier or leaves a single tier - -## Description - -`validateTowerConfig` accepts a step larger than the range (one tier, no temperature change) and a step that does not divide the range (the "Top tier" temperature is never printed). `tierCount` floors the division in `packages/core/src/tower-config.ts:219-220`. Reproduction and observed output are in RPT-004. - -## Acceptance Criteria - -- [ ] A new ADR states whether the end temperature must be reached exactly or is a bound, before any code change -- [ ] validateTowerConfig rejects any config with fewer than 2 tiers -- [ ] A step that does not divide the range is rejected, or the UI labels and STL name show the real top tier, as the ADR decides -- [ ] The config form shows the same problem as validation -- [ ] A unit test covers 230 to 228 step 5 and 230 to 190 step 15 - -## Notes - -## Learnings - -## Progress Log - -- [2026-11-02] Created \ No newline at end of file diff --git a/AGENTS.md b/AGENTS.md index c92714a..ac4a9c7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -43,6 +43,7 @@ Slicer-Agnostic Temperature Tower Generator is a free, 100% client-side browser - In binary output the tier marker is its own comment line `; [temptower] tier ` before a bare `M104`/`M109`, because MeatPack drops inline comments; the ADR-0002 property test runs over the decoded text of a binary input too (ADR-0007). - Geometry and transform read tier boundaries from one shared function over the tower config; no second implementation of `b + i·h` exists (ADR-0005). The transform reads tier starts through `tierStartZ`, which is 0 for tier 0 and `tierBoundaryZ` otherwise (ADR-0009). - The STL base name encodes the tower config, and a round-trip test proves encode/decode is lossless (ADR-0005). +- The end temperature is the top tier: validation rejects fewer than 2 tiers and a step that does not divide the range (ADR-0013). - Config recovery has tests for three cases: a G-code name that keeps the STL base name, a renamed G-code with object-label comments, and neither (manual entry) (ADR-0005). - Geometry tests assert that the mesh is manifold, its height is `b + n·h`, and each tier's label shows that tier's temperature (ADR-0006).