Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .backlog/tasks/complete/TSK-011-fix-tower-config-accepts-a.md
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions .backlog/tasks/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

| Status | Count |
|--------|-------|
| Pending | 6 |
| Pending | 5 |
| Active | 0 |
| Blocked | 0 |
| Complete | 10 |
| Complete | 11 |

## Active Tasks

Expand All @@ -21,14 +21,14 @@ _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

| 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 |
Expand All @@ -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 |
32 changes: 0 additions & 32 deletions .backlog/tasks/pending/TSK-011-fix-tower-config-accepts-a.md

This file was deleted.

1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>` 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).

Expand Down
22 changes: 22 additions & 0 deletions docs/adr/0013-tower-end-temperature-is-reached-exactly.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 17 additions & 1 deletion packages/core/src/tower-config.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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([])
})
})
12 changes: 12 additions & 0 deletions packages/core/src/tower-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading