Skip to content
Draft
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
2 changes: 1 addition & 1 deletion docs/orientation-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ explicit saved mappings remain usable. Newly exported face metadata also keeps
the actual uploaded JPEG. Capture cancellation cannot approve a preview.

The vendored package's source commit and artifact hashes are checked by
`npm run verify:capture-core`. Its EUPL-1.2 license and CubeAssembler MIT notices
`npm run verify:capture-core`. Its `EUPL-1.2 OR AGPL-3.0-or-later` license and CubeAssembler MIT notices
are included; production distribution remains subject to the owner's license
acceptance gate. This slice does not migrate the viewer or the puzzle engine.

Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@fontsource/ibm-plex-mono": "^5.3.0",
"@fontsource/ibm-plex-sans": "^5.3.0",
"@fontsource/space-grotesk": "^5.3.0",
"@puzlwerk/capture-recovery": "file:vendor/puzlwerk-capture-recovery-0.3.0-f1fa30ac.tgz",
"@puzlwerk/capture-recovery": "file:vendor/puzlwerk-capture-recovery-0.4.0-97d0897c.tgz",
"@puzlwerk/viewer": "file:vendor/puzlwerk-viewer-0.1.0-7e14cbd8.tgz",
"fflate": "^0.8.3",
"preact": "^11.2.0"
Expand Down
8 changes: 4 additions & 4 deletions public/licenses/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ <h1>Third-party licenses</h1>
includes) — AGPL-3.0-or-later
</li>
<li>
PuzlWerk capture recovery (compiled PuzlWerk Core, vendored archive 0.3.0) —
<a href="eupl-1.2.LICENSE">EUPL-1.2</a>; the archive was distributed under EUPL-1.2 only. From 2026-11-17 on
PuzlWerk Core is <code>EUPL-1.2 OR AGPL-3.0-or-later</code> at your choice
(<a href="agpl-3.0.LICENSE">AGPL-3.0-or-later</a>); archives 0.1.0 and 0.3.0 stay EUPL-1.2. The archive also
PuzlWerk capture recovery (compiled PuzlWerk Core, vendored archive 0.4.0) —
<code>EUPL-1.2 OR AGPL-3.0-or-later</code> at your choice
(<a href="eupl-1.2.LICENSE">EUPL-1.2</a>, <a href="agpl-3.0.LICENSE">AGPL-3.0-or-later</a>). Archives 0.1.0 and
0.3.0 were distributed under EUPL-1.2 only. The archive also
contains material derived from CubeAssembler, which keeps its MIT license and attribution
(<code>CUBE_ASSEMBLER_LICENSE.txt</code> inside the archive).
</li>
Expand Down
4 changes: 3 additions & 1 deletion scripts/fixtureUploadServer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { join } from 'node:path'
import { fileURLToPath } from 'node:url'

const FACES = ['u', 'r', 'f', 'd', 'l', 'b']
// Same range as CubeSizeRange.maxCubeSize; a test keeps the two equal.
const MAX_CUBE_SIZE = 15
const MAX_BYTES = 30 * 1024 * 1024
const FAVICON = readFileSync(
new URL('./fixtureUploadFavicon.svg', import.meta.url),
Expand Down Expand Up @@ -93,7 +95,7 @@ async function validateFixture(byName) {
if (
!Number.isInteger(n) ||
n < 2 ||
n > 7 ||
n > MAX_CUBE_SIZE ||
!validFacelets(meta.colorsURFDLB, n)
) {
throw new UploadError(400, 'Invalid fixture metadata')
Expand Down
2 changes: 1 addition & 1 deletion src/client/profiles/cubeReviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export function CubeReviewTab({ settings, onChange, photo }: Props) {
setSizes(
sizes.includes(size)
? sizes.filter((s) => s !== size)
: [...sizes, size].sort(),
: [...sizes, size].sort((a, b) => a - b),
)
}
>
Expand Down
3 changes: 0 additions & 3 deletions src/client/scannerAppView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,6 @@ export function ScannerAppView({ model }: { model: ScannerAppModel }) {
e.currentTarget.value = profile.id
}}
>
{puzzleSize === 8 && (
<option value={profile.id}>Imported 8×8 (review only)</option>
)}
<CubeSelectOptions settings={profileStore} />
</select>
<select
Expand Down
6 changes: 0 additions & 6 deletions src/client/useScannerAppModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,6 @@ export function useScannerAppModel() {
// Continue from the first empty slot, or start over when requested (and
// after all six are already complete).
const handleOpenCapture = (restart = false) => {
if (puzzleSize === 8) {
setCaptureMessage(
'8×8 is supported for imported-photo orientation review only. Select a 2×2–7×7 cube for camera capture.',
)
return
}
cancelCaptureIO()
armCaptureAudio()
dismissTurnOverlay()
Expand Down
8 changes: 8 additions & 0 deletions src/core/app/CubeSizeRange.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// The cube sizes the app handles: one source for the profile list, the size
// cookie and the capture and fixture limits. Raise `maxCubeSize` to widen the range.
let minCubeSize = 2
let maxCubeSize = 15

let cubeSizes = Array.fromInitializer(~length=maxCubeSize - minCubeSize + 1, i => minCubeSize + i)

let isSupportedSize = size => size >= minCubeSize && size <= maxCubeSize
4 changes: 4 additions & 0 deletions src/core/app/CubeSizeRange.resi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@genType let minCubeSize: int
@genType let maxCubeSize: int
@genType let cubeSizes: array<int>
@genType let isSupportedSize: int => bool
9 changes: 7 additions & 2 deletions src/core/app/Preferences.res
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ let selectionCookie = (name, value) => `${name}=${encodeURIComponent(value)}; ${

let selectedCubeSize = cookies =>
switch readSelectionOption(cookies, cubeSizeCookie) {
| Some(("2" | "3" | "4" | "5" | "6" | "7") as value) => Null.make(Float.parseFloat(value))
| _ => Null.null
| Some(value) =>
switch Int.fromString(value) {
| Some(size) if Int.toString(size) == value && CubeSizeRange.isSupportedSize(size) =>
Null.make(Int.toFloat(size))
| _ => Null.null
}
| None => Null.null
}

type cubeView =
Expand Down
7 changes: 5 additions & 2 deletions src/core/capture/CaptureFaceMapping.res
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,11 @@ let assignMapping = (mapping: mapping, slot, target) =>

let validateMapping = (captured: Dict.t<grid>, mapping: mapping, size): validation => {
let issues = []
if size < 2 || size > 8 {
issues->Array.push("Manual face mapping supports sizes 2 through 8.")
if !CubeSizeRange.isSupportedSize(size) {
let (lo, hi) = (CubeSizeRange.minCubeSize, CubeSizeRange.maxCubeSize)
issues->Array.push(
`Manual face mapping supports sizes ${Int.toString(lo)} through ${Int.toString(hi)}.`,
)
}
if Array.length(mapping) != 6 {
issues->Array.push("Assign all six captured photos.")
Expand Down
7 changes: 4 additions & 3 deletions src/core/capture/FixtureZip.res
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ let fixtureLayout = (request: fixtureRequest, now: string) => {
if (
!Float.isFinite(gridSize) ||
Math.floor(gridSize) != gridSize ||
gridSize < 2.0 ||
gridSize > 8.0
gridSize < Int.toFloat(CubeSizeRange.minCubeSize) ||
gridSize > Int.toFloat(CubeSizeRange.maxCubeSize)
) {
fail("gridSize must be an integer between 2 and 8")
let (lowest, highest) = (CubeSizeRange.minCubeSize, CubeSizeRange.maxCubeSize)
fail(`gridSize must be an integer between ${Int.toString(lowest)} and ${Int.toString(highest)}`)
}
let size = Float.toString(gridSize)
[
Expand Down
3 changes: 1 addition & 2 deletions src/core/capture/GuidedCaptureProtocol.res
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ let placedFaces = (captured, placements: CaptureFaceMapping.mapping) =>
)->fromGeometry
let seedForMapping = (captured: Dict.t<grid>, size, placements): seed => {
let complete =
size >= 2 &&
size <= 8 &&
CubeSizeRange.isSupportedSize(size) &&
slots->Array.every(slot =>
captured
->Dict.get(slot)
Expand Down
18 changes: 4 additions & 14 deletions src/core/profiles/ProfileSettings.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type profileSettings = {
autoMatchedColorsId?: string,
}

let cubeSizes = [2, 3, 4, 5, 6, 7]
let cubeSizes = CubeSizeRange.cubeSizes
let autoColorsId = "auto-colors"
let captureColorsId = "capture-colors"
let colorKeys = ["W", "Y", "O", "R", "G", "B"]
Expand Down Expand Up @@ -93,19 +93,9 @@ let builtinCubes = cubeSizes->Array.map(size =>
})
)

// Imported 8x8 captures can be corrected without adding a camera-size option.
// Keep one stable profile object so live effects do not retrigger per render.
let importedEight = freeze({
id: "imported-generic-8",
name: "Imported 8×8 (review only)",
size: 8,
sampling: freeze({stickerCore: 0.6}),
})

let builtinCube = size =>
switch builtinCubes->Array.find(cube => cube.size == size) {
| Some(cube) => cube
| None if size == 8 => importedEight
| None => fail("Unsupported cube size")
}

Expand Down Expand Up @@ -153,7 +143,7 @@ let activeCube = (settings: profileSettings, size) => {
let validCubeSetting = (cube: cubeSetting) =>
cube.id != "" &&
cube.name->String.trim != "" &&
cubeSizes->Array.includes(cube.size) &&
CubeSizeRange.isSupportedSize(cube.size) &&
Float.isFinite(cube.sampling.stickerCore) &&
cube.sampling.stickerCore > 0.0 &&
cube.sampling.stickerCore <= 1.0
Expand Down Expand Up @@ -435,7 +425,7 @@ let parseCube = (value: Untrusted.t) =>
| (Some(id), Some(name), Some(size), Some(stickerCore))
if name->String.trim != "" &&
isInteger(size) &&
cubeSizes->Array.includes(Float.toInt(size)) &&
CubeSizeRange.isSupportedSize(Float.toInt(size)) &&
Float.isFinite(stickerCore) &&
stickerCore > 0.0 &&
stickerCore <= 1.0 =>
Expand Down Expand Up @@ -490,7 +480,7 @@ let parseProfileSettings = (value: Untrusted.t) =>
->Array.forEach(((key, id)) =>
switch (Int.fromString(key), Untrusted.string(id)) {
| (Some(size), Some(id))
if cubeSizes->Array.includes(size) &&
if CubeSizeRange.isSupportedSize(size) &&
Int.toString(size) == key &&
[...cubes, builtinCube(size)]->Array.some(cube => cube.id == id && cube.size == size) =>
activeCubeBySize->Dict.set(key, id)
Expand Down
19 changes: 19 additions & 0 deletions test/captureFaceMapping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ describe('manual captured-face mapping', () => {
})
})

describe('manual mapping size range', () => {
it.each(Array.from({ length: 14 }, (_, i) => i + 2))(
'accepts a %ix%i cube',
(n) => {
const raw = solved(n)
const result = validateMapping(raw, initializeMapping(raw, null), n)
expect(result.issues.join(' ')).not.toMatch(/supports sizes/)
},
)
it.each([1, 16, 17])('refuses size %i with the supported range', (n) => {
const raw = solved(Math.max(n, 2))
const result = validateMapping(raw, initializeMapping(raw, null), n)
expect(result.valid).toBe(false)
expect(result.issues).toContain(
'Manual face mapping supports sizes 2 through 15.',
)
})
})

describe('capture-relative display frame', () => {
it('keeps canonical faces intact and records exact invertible transforms', () => {
const raw = asymmetric(3)
Expand Down
17 changes: 17 additions & 0 deletions test/cubeProfileReview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,20 @@ describe('deleting cubes', () => {
expect(unusedCubes(BASE)).toEqual(['warm', 'gan', 'gocube', 'big'])
})
})

describe('review of cubes of size 8 through 15', () => {
it.each([8, 9, 12, 15])(
'groups a saved %ix%i cube with its Generic cube and names the fallback when deleting it',
(size) => {
const saved = settings([cube(`mine-${size}`, size, 0.6)], {
[size]: `mine-${size}`,
})
expect(ids(duplicateCubeGroups(saved, 0.02))).toEqual([
[`builtin-generic-${size}`, `mine-${size}`].sort(),
])
expect(cubeDeletionEffects(saved, [`mine-${size}`])).toEqual([
`${size}×${size} then uses Generic ${size}×${size}`,
])
},
)
})
33 changes: 30 additions & 3 deletions test/fixtureUploadServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { once } from 'node:events'
import type { Server } from 'node:http'
import { maxCubeSize } from '../src/core/app/CubeSizeRange.gen'
import { createFixtureUploadServer } from '../scripts/fixtureUploadServer.mjs'

const FACE_KEYS = ['u', 'r', 'f', 'd', 'l', 'b']
const JPEG = new Uint8Array([0xff, 0xd8, 0xff, 0xd9])

function fixtureForm(name = 'capture-test'): FormData {
function fixtureForm(name = 'capture-test', gridSize = 3): FormData {
const form = new FormData()
form.set('name', name)
const faces = Object.fromEntries(
FACE_KEYS.map((face) => [face, { photo: `face-${face}.jpg` }]),
)
const meta = {
gridSize: 3,
colorsURFDLB: FACE_KEYS.map((_, i) => 'WROGYB'[i].repeat(9)).join(' '),
gridSize,
colorsURFDLB: FACE_KEYS.map((_, i) =>
'WROGYB'[i].repeat(gridSize * gridSize),
).join(' '),
faces,
}
form.append(
Expand Down Expand Up @@ -94,6 +97,30 @@ describe('local fixture upload server', () => {
expect((await fetch(`${url}/meta.json`)).status).toBe(404)
})

it.each(Array.from({ length: 14 }, (_, i) => i + 2))(
'accepts a %ix%i fixture',
async (size) => {
await start()
expect((await upload(fixtureForm(`size-${size}`, size))).status).toBe(201)
},
)

it('accepts the largest app size and refuses the next one', async () => {
await start()
expect(maxCubeSize).toBe(15)
expect((await upload(fixtureForm('edge', maxCubeSize))).status).toBe(201)
expect((await upload(fixtureForm('over', maxCubeSize + 1))).status).toBe(
400,
)
})

it.each([1, 16, 17])('refuses a %ix%i fixture', async (size) => {
await start()
const response = await upload(fixtureForm('too-big', size))
expect(response.status).toBe(400)
expect(await readdir(root!)).toEqual([])
})

it('stores size-prefixed fixture names as directory names', async () => {
await start()
const name = 'cube-3x3-2026-09-27T08-55-46'
Expand Down
28 changes: 28 additions & 0 deletions test/fixtureZip.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,34 @@ describe('fixture zips', () => {
).toBe('cube-2x2-2026-09-27T08-55-46')
})

it.each(Array.from({ length: 14 }, (_, i) => i + 2))(
'builds a fixture for a %ix%i cube',
(size) => {
const face = 'W'.repeat(size * size)
const fixture = buildFixture(
request({
name: 'sized',
gridSize: size,
colorsURFDLB: Array(6).fill(face).join(' '),
}),
)
expect(fixture.name).toBe('sized')
},
)

it.each([1, 16, 17])('refuses a grid size of %i', (size) => {
expect(() =>
buildFixture(
request({
gridSize: size,
colorsURFDLB: Array(6)
.fill('W'.repeat(size * size))
.join(' '),
}),
),
).toThrow('gridSize must be an integer between 2 and 15')
})

it('keeps explicit fixture names path-safe', () => {
expect(buildFixture(request({ name: '../../etc/passwd' })).name).toBe(
'------etc-passwd',
Expand Down
2 changes: 1 addition & 1 deletion test/guidedCaptureProtocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ it('independently derives every source and pixel orientation from the physical 3
})
}
})
for (const size of [2, 3, 4, 5, 6, 7])
for (const size of Array.from({ length: 14 }, (_, i) => i + 2))
for (const mirrored of [false, true]) {
it(`preserves the exact physical ${size}×${size} assembly with mirror=${mirrored}`, () => {
let original = solvedCubeFaces(size, {
Expand Down
Loading
Loading