Shadow comparison: exact cursor saved after every page; a resume can only start there
The report (positionReached, every mismatch position, the runs so far) is saved safely after each compared page. orbit_shadow_resume picks up from the saved position; a start anywhere else, a resume without a report, or one after the end is refused and noted in resume-refused.txt. verify.sh now builds clean: incremental builds had left stale Compose stability checks in two earlier APKs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -54,6 +54,31 @@ class ShadowSafetyTest {
|
||||
val progress = mutableListOf<Int>()
|
||||
CatalogueShadow.compare({ s, _, _ -> CataloguePage(emptyList(), 10, 1_000) }, { s, _, _ -> CataloguePage(emptyList(), 10, 1_000) }, 100,
|
||||
onProgress = { assertTrue(it.getBoolean("running")); progress += it.getInt("pages") })
|
||||
assertEquals(listOf(25, 50, 75), progress)
|
||||
assertEquals((1..99).toList(), progress) // saved after every compared page; the 100th is the final report
|
||||
}
|
||||
|
||||
@Test fun theSavedPositionIsAlwaysTheLastComparedPage() {
|
||||
val saved = mutableListOf<Long>(); var reads = 0
|
||||
// The provider fails for good on the sixth page: five pages were compared, so 1,000 is the last verified position.
|
||||
val r = CatalogueShadow.compare(reader, { s, n, w -> reads++; if (s >= 1_000) throw java.io.IOException("down") else reader(s, n, w) }, 100,
|
||||
onProgress = { saved += it.getLong("positionReached") })
|
||||
assertEquals(listOf(200L, 400L, 600L, 800L, 1_000L), saved)
|
||||
assertEquals(1_000L, r.getLong("positionReached")); assertEquals(5, r.getInt("pages"))
|
||||
}
|
||||
|
||||
@Test fun aResumeStartsOnlyAtTheLastVerifiedPosition() {
|
||||
fun report(at: Long, total: Long? = 2_000L) = org.json.JSONObject().put("positionReached", at).put("total", total ?: org.json.JSONObject.NULL)
|
||||
assertEquals(1_000L to null, CatalogueShadow.resumePoint(report(1_000), null))
|
||||
assertEquals(1_000L to null, CatalogueShadow.resumePoint(report(1_000), 1_000))
|
||||
assertTrue(CatalogueShadow.resumePoint(report(1_000), 1_200).second!!.contains("last verified position is 1000")) // can't skip ahead
|
||||
assertTrue(CatalogueShadow.resumePoint(report(1_000), 800).second!!.startsWith("refused")) // or go back unasked
|
||||
assertTrue(CatalogueShadow.resumePoint(null, null).second!!.startsWith("refused")) // nothing to resume
|
||||
assertTrue(CatalogueShadow.resumePoint(report(2_000), null).second!!.contains("already reached the end"))
|
||||
assertTrue(CatalogueShadow.resumePoint(org.json.JSONObject(), null).second!!.startsWith("refused"))
|
||||
}
|
||||
|
||||
@Test fun everyMismatchPositionIsKept() {
|
||||
val r = CatalogueShadow.compare(reader, { s, n, w -> CataloguePage(emptyList(), page(s).rawCount, total + 1) }, 100)
|
||||
assertEquals(10, r.getInt("mismatches")); assertEquals(10, r.getJSONArray("mismatchPositions").length())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user