Skip to content

Commit 51d6b5f

Browse files
committed
test(host): pin the sentence a refused state write answers with
`store.save()` refuses a temp name that is not a plain file of its own with one sentence that names the temp path: it is what a Bot, and through it the user, reads to learn why nothing was saved. The three cases that reach that guard — a directory, a symbol link and a hard link at the temp name — asserted only that the save rejects, so the sentence could be rewritten, or the error swapped for another class or given a code, with all three still green. Each keeps its `assert.rejects` and now validates the error's name, the absence of a code, and the message word for word through one shared constant.
1 parent 2eb9661 commit 51d6b5f

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎core/test/store.test.js‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ function runtime(t, saved, { home: at, config } = {}) {
6262
return { rt, home, statePath, warnings, dispose }
6363
}
6464

65+
// The one sentence a save that refuses to write answers with. A temp name that is a directory, a
66+
// symbol link or a hard link all reach the same guard, so the sentence is written once and checked
67+
// word for word: it is what a Bot, and through it the user, reads to learn why nothing was saved.
68+
const TEMP_REFUSAL = 'is not a plain file of its own, so the Bot team was not written there.'
69+
70+
function refusedTempName(statePath) {
71+
return (error) => {
72+
assert.equal(error.name, 'Error', 'the refusal is a plain Error')
73+
assert.equal(error.code, undefined, 'the refusal carries no code')
74+
assert.equal(error.message, `Not saved: ${statePath}.${process.pid}.tmp ${TEMP_REFUSAL}`)
75+
return true
76+
}
77+
}
78+
6579
// P-556 (Chief's ruling: no write-through): the store never writes through a link. The rename
6680
// replaces the name, link included, so the target keeps every byte and its last write time, and the
6781
// path a person opened is a regular file of this home's own from that save on.
@@ -138,7 +152,7 @@ test('a failed state write rejects and leaves the saved file unchanged', async (
138152
const original = fs.readFileSync(statePath)
139153
fs.mkdirSync(`${statePath}.${process.pid}.tmp`)
140154
rt.state.prefs.marker = 'not saved'
141-
await assert.rejects(rt.save())
155+
await assert.rejects(rt.save(), refusedTempName(statePath))
142156
assert.deepEqual(fs.readFileSync(statePath), original)
143157
})
144158

@@ -488,7 +502,7 @@ test('a linked state temp name does not take the save; the state file stays a pl
488502
fs.writeFileSync(outside, 'OUTSIDE\n')
489503
fs.symlinkSync(outside, `${statePath}.${process.pid}.tmp`)
490504
rt.state.prefs.sweep = 'not saved'
491-
await assert.rejects(rt.save())
505+
await assert.rejects(rt.save(), refusedTempName(statePath))
492506
assert.equal(fs.readFileSync(outside, 'utf8'), 'OUTSIDE\n', 'the file behind the temp link is not written through')
493507
assert.equal(fs.lstatSync(statePath).isSymbolicLink(), false, 'the state file is still a plain file')
494508
assert.equal(JSON.parse(fs.readFileSync(statePath, 'utf8')).prefs.sweep, undefined, 'the refused save did not land')
@@ -525,7 +539,7 @@ test('a hard link at the state temp name is refused; the save never reaches the
525539
fs.writeFileSync(outside, 'OUTSIDE\n')
526540
fs.linkSync(outside, `${statePath}.${process.pid}.tmp`)
527541
rt.state.prefs.sweep = 'not saved'
528-
await assert.rejects(rt.save())
542+
await assert.rejects(rt.save(), refusedTempName(statePath))
529543
assert.equal(fs.readFileSync(outside, 'utf8'), 'OUTSIDE\n', 'the shared inode keeps its bytes')
530544
assert.equal(fs.lstatSync(outside).nlink, 2, 'the outside file still carries the temp name')
531545
assert.equal(fs.readFileSync(statePath, 'utf8'), before, 'the state file kept what it had')

‎patches/ds-bot/0014-flybot-branding.patch‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,10 +2261,24 @@ diff --git a/test/store.test.js b/test/store.test.js
22612261
autoRoomName: () => 'Room',
22622262
retitleRoom: async () => {},
22632263
warn: (...args) => warnings.push(args),
2264-
@@ -61,6 +61,75 @@ function runtime(t, saved) {
2264+
@@ -61,6 +61,89 @@ function runtime(t, saved) {
22652265
return { rt, home, statePath, warnings, dispose }
22662266
}
22672267

2268+
+// The one sentence a save that refuses to write answers with. A temp name that is a directory, a
2269+
+// symbol link or a hard link all reach the same guard, so the sentence is written once and checked
2270+
+// word for word: it is what a Bot, and through it the user, reads to learn why nothing was saved.
2271+
+const TEMP_REFUSAL = 'is not a plain file of its own, so the Bot team was not written there.'
2272+
+
2273+
+function refusedTempName(statePath) {
2274+
+ return (error) => {
2275+
+ assert.equal(error.name, 'Error', 'the refusal is a plain Error')
2276+
+ assert.equal(error.code, undefined, 'the refusal carries no code')
2277+
+ assert.equal(error.message, `Not saved: ${statePath}.${process.pid}.tmp ${TEMP_REFUSAL}`)
2278+
+ return true
2279+
+ }
2280+
+}
2281+
+
22682282
+// P-556 (Chief's ruling: no write-through): the store never writes through a link. The rename
22692283
+// replaces the name, link included, so the target keeps every byte and its last write time, and the
22702284
+// path a person opened is a regular file of this home's own from that save on.
@@ -2342,7 +2356,7 @@ diff --git a/test/store.test.js b/test/store.test.js
23422356
fs.mkdirSync(`${statePath}.${process.pid}.tmp`)
23432357
rt.state.prefs.marker = 'not saved'
23442358
- await assert.rejects(rt.save(), { code: 'EISDIR' })
2345-
+ await assert.rejects(rt.save())
2359+
+ await assert.rejects(rt.save(), refusedTempName(statePath))
23462360
assert.deepEqual(fs.readFileSync(statePath), original)
23472361
})
23482362

@@ -2499,7 +2513,7 @@ diff --git a/test/store.test.js b/test/store.test.js
24992513
+ fs.writeFileSync(outside, 'OUTSIDE\n')
25002514
+ fs.symlinkSync(outside, `${statePath}.${process.pid}.tmp`)
25012515
+ rt.state.prefs.sweep = 'not saved'
2502-
+ await assert.rejects(rt.save())
2516+
+ await assert.rejects(rt.save(), refusedTempName(statePath))
25032517
+ assert.equal(fs.readFileSync(outside, 'utf8'), 'OUTSIDE\n', 'the file behind the temp link is not written through')
25042518
+ assert.equal(fs.lstatSync(statePath).isSymbolicLink(), false, 'the state file is still a plain file')
25052519
+ assert.equal(JSON.parse(fs.readFileSync(statePath, 'utf8')).prefs.sweep, undefined, 'the refused save did not land')
@@ -2536,7 +2550,7 @@ diff --git a/test/store.test.js b/test/store.test.js
25362550
+ fs.writeFileSync(outside, 'OUTSIDE\n')
25372551
+ fs.linkSync(outside, `${statePath}.${process.pid}.tmp`)
25382552
+ rt.state.prefs.sweep = 'not saved'
2539-
+ await assert.rejects(rt.save())
2553+
+ await assert.rejects(rt.save(), refusedTempName(statePath))
25402554
+ assert.equal(fs.readFileSync(outside, 'utf8'), 'OUTSIDE\n', 'the shared inode keeps its bytes')
25412555
+ assert.equal(fs.lstatSync(outside).nlink, 2, 'the outside file still carries the temp name')
25422556
+ assert.equal(fs.readFileSync(statePath, 'utf8'), before, 'the state file kept what it had')

0 commit comments

Comments
 (0)