b8f30916f471

break same-second ties in the connected machines list and its prune by insertion order, so twenty-one redemptions in one second keep the latest twenty (v3.0.80)

time
2026-09-28 12:22 UTC · 2 weeks ago
machine
Junes-MacBook-Pro.local
agent
claude-opus-5-5
session
last twenty machines ties
parent
4e46c3606ea7
4 files package.json+1 −1src/admin/console.ts+1 −1src/server/connect.ts+1 −1tests/connect.test.ts+18 −0
package.json+1 −1
@@ -1,6 +1,6 @@11 {22 	"name": "kepr",3-	"version": "3.0.79",3+	"version": "3.0.80",44 	"private": true,55 	"type": "module",66 	"scripts": {

view file

src/admin/console.ts+1 −1
@@ -73,7 +73,7 @@7373 		.query<{ machine: string; used_at: number }, [number]>(7474 			`SELECT machine, used_at FROM connect_codes7575 			 WHERE used_at IS NOT NULL76-			 ORDER BY used_at DESC76+			 ORDER BY used_at DESC, rowid DESC7777 			 LIMIT ?`,7878 		)7979 		.all(MACHINES_LISTED);

view file

src/server/connect.ts+1 −1
@@ -143,7 +143,7 @@143143 				 AND code_hash NOT IN (144144 					SELECT code_hash FROM connect_codes145145 					WHERE used_at IS NOT NULL146-					ORDER BY used_at DESC146+					ORDER BY used_at DESC, rowid DESC147147 					LIMIT ?148148 				 )`,149149 			)

view file

tests/connect.test.ts+18 −0
@@ -354,4 +354,22 @@354354 		expect(kept.length).toBe(20);355355 		expect(kept[0]?.machine).toBe("machine-2");356356 	});357+358+	test("redemptions in one second keep and list the latest twenty", async () => {359+		const { app, browser, kepr } = await connected();360+		for (let i = 0; i < 22; i++) {361+			const { code } = await issue(browser, `machine-${i}`);362+			expect((await redeem(app, code, `10.0.1.${i + 1}`)).status).toBe(200);363+		}364+		const html = await (await browser.get("/admin")).text();365+		expect(html).not.toContain("machine-1 ");366+		expect(html.indexOf("machine-21")).toBeLessThan(html.indexOf("machine-2 "));367+		const kept = kepr368+			.query<{ machine: string }, []>("SELECT machine FROM connect_codes WHERE used_at IS NOT NULL")369+			.all()370+			.map((row) => row.machine);371+		expect(kept).not.toContain("machine-0");372+		expect(kept).not.toContain("machine-1");373+		expect(kept.length).toBe(20);374+	});357375 });

view file