Coach: was durch das Gatter kam, weil es nur gezaehlt und nicht geprueft wurde
Vier Stellen, eine Ursache: strukturierte `after`-Werte werden auf Zugehoerigkeit
geprueft, aber nicht auf die Form-Invarianten, die der Apply-Pfad voraussetzt.
Skalare Aenderungen sind dicht, die zusammengesetzten waren es nicht.
reorder akzeptierte doppelte Ids. ['0001','0001'] hat die richtige Laenge, jede Id
ist enthalten — Server und Client liessen es durch, die dritte Uebung war weg und
die verbliebene stand als dasselbe Objekt in zwei Slots. Ausgerechnet der einzige
Aenderungstyp, fuer den changeValues() null liefert: im Review-Screen ist kein
Vorher/Nachher zu sehen, das es haette verraten koennen. Jetzt Set-Vergleich auf
beiden Seiten.
superset konnte eine Uebung mit sich selbst verknuepfen. Der Partner-Splice nimmt
den Anker unter sich weg, danach schreibt das Tagging durch einen Index, der nicht
mehr aufloest — TypeError nach halbem Umsortieren. Der Client-Test prueft die
Meldung, nicht nur dass geworfen wird: geworfen hat der Bug auch.
add-routine hat unbekannte Exercise-Ids stillschweigend herausgefiltert, waehrend
validatePlan bei derselben Sache abbricht. Das ist FR-16, und es gilt hier genauso:
sonst bekommt jemand die Routine ohne die Uebungen, die es nicht geben konnte,
unter der Summary derjenigen, die er gesehen hat.
`before` war das einzige Feld, das ungeprueft durch das Gatter ging — ein Objekt
beliebiger Groesse landet im synchronisierten Coach-Log, ein bloss falsch getyptes
("3 sets" statt 3) laesst markStale eine voellig gute Aenderung deaktivieren. Der
Plan liegt im Validator bereits vor, also wird `before` dort gelesen statt von der
Antwort uebernommen.
api 68/68, frontend 404/404, Build sauber, Library in sync bei 1324.
This commit is contained in:
1 parent
34d41b8e64
commit
9082ac5a2d
4 files changed
+110
-7
No files matched your search
@@ -307,7 +307,10 @@ const CHANGE_APPLY = {
|
||||
const r = need(findRoutine(s, c.target.routineId))
|
||||
const by = new Map(r.ex.map(e => [e.id, e]))
|
||||
const next = c.after.map(id => by.get(id)).filter(Boolean)
|
||||
if (next.length !== r.ex.length) throw new Error('incomplete reorder')
|
||||
// Distinct exercises, not just the right count: an order naming one id twice maps to the
|
||||
// same object twice and still counts right, which drops an exercise and leaves the
|
||||
// survivor aliased into two slots that then edit each other.
|
||||
if (next.length !== r.ex.length || new Set(next).size !== r.ex.length) throw new Error('incomplete reorder')
|
||||
r.ex = next
|
||||
cleanupSg(r.ex)
|
||||
},
|
||||
@@ -316,6 +319,9 @@ const CHANGE_APPLY = {
|
||||
const i = r.ex.findIndex(e => e.id === c.target.exId)
|
||||
if (i < 0) throw new Error('missing exercise')
|
||||
if (!c.after?.link) { delete r.ex[i].sg; cleanupSg(r.ex); return }
|
||||
// Splicing the partner out from under the anchor when they are the same exercise leaves
|
||||
// nothing to tag; refuse rather than reorder the routine on the way to a TypeError.
|
||||
if (c.after.with === c.target.exId) throw new Error('superset with itself')
|
||||
const j = r.ex.findIndex(e => e.id === c.after.with)
|
||||
if (j < 0) throw new Error('missing partner')
|
||||
// Supersets are a property of adjacency in this app; move the partner next to it first.
|
||||
|
||||
@@ -208,6 +208,21 @@ describe('applying changes', () => {
|
||||
const out = apply(state(), proposal([change({ type: 'reorder', target: { routineId: 'r1' }, after: ['0009', '0001', '0007'] })]), ['c1'])
|
||||
expect(out.routines[0].ex.map(e => e.id)).toEqual(['0009', '0001', '0007'])
|
||||
expect(() => apply(state(), proposal([change({ type: 'reorder', target: { routineId: 'r1' }, after: ['0009'] })]), ['c1'])).toThrow()
|
||||
// A repeated id counts right and resolves to the same object twice: the third exercise
|
||||
// disappears and the survivor is aliased into two slots. Both gates have to catch this,
|
||||
// because it is the one change type with nothing in the diff column to give it away.
|
||||
expect(() => apply(state(), proposal([change({
|
||||
type: 'reorder', target: { routineId: 'r1' }, after: ['0009', '0009', '0001']
|
||||
})]), ['c1'])).toThrow()
|
||||
})
|
||||
|
||||
it('refuses to superset an exercise with itself', () => {
|
||||
// Reachable only if the server let it past. By the message, not merely by throwing: the
|
||||
// unfixed path also threw — a TypeError, after it had already moved the exercise — so
|
||||
// asserting "it throws" would pass against the bug this is here to pin.
|
||||
expect(() => apply(state(), proposal([change({
|
||||
type: 'superset', after: { link: true, with: '0001' }
|
||||
})]), ['c1'])).toThrow('superset with itself')
|
||||
})
|
||||
|
||||
it('supersets by moving the partner adjacent and tagging both', () => {
|
||||
|
||||
Reference in new issue
Block a user