tods-competition-factory 7.25.0 → 7.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -142,7 +142,7 @@ Full documentation with interactive examples: **[courthive.github.io/competition
142
142
 
143
143
  ## Testing
144
144
 
145
- **20,000+ tests** run on every change (18,000+ in the default suite, plus 1,500+ TEAM-competition arms), covering draw generation and exit propagation, scheduling, scoring, participants and entries, team competition, publishing and embargo, ranking points and ratings, officiating and sanctioning.
145
+ **22,000+ tests** run on every change (21,000+ in the default suite, plus 1,500+ TEAM-competition arms), covering draw generation and exit propagation, scheduling, scoring, participants and entries, team competition, publishing and embargo, ranking points and ratings, officiating and sanctioning.
146
146
 
147
147
  Beyond conventional unit and integration tests, the suite includes relational property suites (do/undo, idempotence, monotonicity), agreement oracles, and an at-scale randomized sweep with delta-debugging for exit propagation — added because full branch coverage of a propagation guard proved compatible with hundreds of wrong answers.
148
148
 
@@ -26,9 +26,8 @@ function applyOwnedPlan({ shape, args, ops, }) {
26
26
  op.op === 'exchangeDrawPositions'
27
27
  ? [op.matchUpId]
28
28
  : []);
29
- const written = [
30
- ...new Set(ops.flatMap((op) => (op.op === 'setMatchUpResult' && !op.announcedAs ? [op.matchUpId] : []))),
31
- ];
29
+ const scored = ops.flatMap((op) => (op.op === 'setMatchUpResult' && !op.announcedAs ? [op.matchUpId] : []));
30
+ const written = [...new Set(scored.toReversed())].reverse();
32
31
  const announced = [...new Set(writes.toReversed())].reverse();
33
32
  const lastWrites = new Map(ops.flatMap((op) => ('matchUpId' in op ? [[op.matchUpId, op.op]] : [])));
34
33
  const placedLast = new Set([...lastWrites].flatMap(([matchUpId, op]) => (op === 'setMatchUpDrawPositions' ? [matchUpId] : [])));
@@ -37,26 +36,9 @@ function applyOwnedPlan({ shape, args, ops, }) {
37
36
  const recoded = new Set(ops.flatMap((op) => (op.op === 'setMatchUpStatusCodes' ? [op.matchUpId] : [])));
38
37
  const exchanged = new Set(ops.flatMap((op) => (op.op === 'exchangeDrawPositions' ? [op.matchUpId] : [])));
39
38
  const relayed = new Set(ops.flatMap((op) => (op.op === 'mergeSideExitProvenance' ? [op.matchUpId] : [])));
40
- const removed = new Map(ops.flatMap((op) => op.op === 'setMatchUpDrawPositions' && op.removedDrawPosition && !op.placedDrawPosition
41
- ? [[op.matchUpId, op.removedDrawPosition]]
42
- : []));
43
- const unevented = new Set(ops.flatMap((op) => (op.op === 'setMatchUpDrawPositions' && (op.announcesContext === false || op.advancesThroughBye)) ||
44
- (op.op === 'setMatchUpResult' && op.announcesContext === false) ||
45
- (op.op === 'setMatchUpBye' && op.announcesEvent === false) ||
46
- (op.op === 'setSideLineUp' && op.announcesEvent === false)
47
- ? [op.matchUpId]
48
- : []));
49
- const untournamented = new Set(ops.flatMap((op) => (op.op === 'setMatchUpDrawPositions' || op.op === 'setMatchUpResult') && op.announcesContext === false
50
- ? [op.matchUpId]
51
- : []));
39
+ const { removed, unevented, untournamented, unbyed, settledResults } = noticeRules(ops);
52
40
  const advanced = new Set(ops.flatMap((op) => (op.op === 'setMatchUpDrawPositions' && op.advancesThroughBye ? [op.matchUpId] : [])));
53
- const unbyed = new Map();
54
- for (const op of ops) {
55
- if (op.op === 'clearMatchUpBye')
56
- unbyed.set(op.matchUpId, op.drawPosition);
57
- if (op.op === 'setMatchUpDrawPositions' && op.withdrawnByePosition)
58
- unbyed.set(op.matchUpId, op.withdrawnByePosition);
59
- }
41
+ const released = new Set(ops.flatMap((op) => (op.op === 'setMatchUpDrawPositions' && op.releasedDrawPosition ? [op.matchUpId] : [])));
60
42
  const stored = new Map(args.matchUpsMap?.drawMatchUps.map((matchUp) => [matchUp.matchUpId, matchUp]));
61
43
  const subscribed = getTopics().topics.includes(UPDATE_INCONTEXT_MATCHUP);
62
44
  for (const matchUpId of written) {
@@ -70,18 +52,15 @@ function applyOwnedPlan({ shape, args, ops, }) {
70
52
  matchUpId,
71
53
  });
72
54
  }
73
- const settled = new Map(ops.flatMap((op) => {
74
- if (op.op === 'setSideLineUp')
75
- return [[op.matchUpId, op.announcedAs]];
76
- return op.op === 'setMatchUpResult' && op.announcedAs ? [[op.matchUpId, op.announcedAs]] : [];
77
- }));
55
+ const { settled } = namedWriters(ops);
78
56
  for (const matchUpId of announced) {
79
57
  const matchUp = stored.get(matchUpId);
80
58
  if (!matchUp)
81
59
  continue;
82
60
  const removedPosition = resulted.has(matchUpId) ? undefined : removed.get(matchUpId);
83
61
  const unbyedPosition = resulted.has(matchUpId) ? undefined : unbyed.get(matchUpId);
84
- const noticeEvent = removedPosition || unbyedPosition || unevented.has(matchUpId) ? undefined : event;
62
+ const settledWrite = settledResults.has(matchUpId);
63
+ const noticeEvent = !settledWrite && (removedPosition || unbyedPosition || unevented.has(matchUpId)) ? undefined : event;
85
64
  modifyMatchUpNotice({
86
65
  context: settled.get(matchUpId) ??
87
66
  noticeContext(matchUpId, removedPosition, unbyedPosition, {
@@ -91,9 +70,10 @@ function applyOwnedPlan({ shape, args, ops, }) {
91
70
  exchanged,
92
71
  relayed,
93
72
  advanced,
73
+ released,
94
74
  }),
95
75
  eventId: noticeEvent?.eventId,
96
- tournamentId: untournamented.has(matchUpId) || unbyedPosition ? undefined : tournamentId,
76
+ tournamentId: !settledWrite && (untournamented.has(matchUpId) || unbyedPosition) ? undefined : tournamentId,
97
77
  drawDefinition,
98
78
  matchUp,
99
79
  event: noticeEvent,
@@ -103,9 +83,46 @@ function applyOwnedPlan({ shape, args, ops, }) {
103
83
  const tieMatchUpResult = dualTallyResult(ops);
104
84
  return shape === 'direction' ? { ...SUCCESS, context: {}, ...tieMatchUpResult } : { ...SUCCESS, ...tieMatchUpResult };
105
85
  }
86
+ function noticeRules(ops) {
87
+ const removed = new Map(ops.flatMap((op) => op.op === 'setMatchUpDrawPositions' && op.removedDrawPosition && !op.placedDrawPosition
88
+ ? [[op.matchUpId, op.removedDrawPosition]]
89
+ : []));
90
+ const unevented = new Set(ops.flatMap((op) => (op.op === 'setMatchUpDrawPositions' &&
91
+ (op.announcesContext === false || (op.advancesThroughBye && !op.announcesEvent))) ||
92
+ (op.op === 'setMatchUpResult' && op.announcesContext === false) ||
93
+ (op.op === 'setMatchUpBye' && op.announcesEvent === false)
94
+ ? [op.matchUpId]
95
+ : []));
96
+ const untournamented = new Set(ops.flatMap((op) => (op.op === 'setMatchUpDrawPositions' || op.op === 'setMatchUpResult') && op.announcesContext === false
97
+ ? [op.matchUpId]
98
+ : []));
99
+ const unbyed = withdrawnByeNotices(ops);
100
+ for (const matchUpId of namedWriters(ops).lineUpUnevented)
101
+ unevented.add(matchUpId);
102
+ const settledResults = new Set(ops.flatMap((op) => (op.op === 'setMatchUpResult' && op.announcedAs ? [op.matchUpId] : [])));
103
+ return { removed, unevented, untournamented, unbyed, settledResults };
104
+ }
105
+ function eventlessNotices(ops) {
106
+ const { removed, unevented, unbyed, settledResults } = noticeRules(ops);
107
+ const resulted = new Set(ops.flatMap((op) => (op.op === 'setMatchUpResult' ? [op.matchUpId] : [])));
108
+ const matchUps = new Set(ops.flatMap((op) => {
109
+ if (!('matchUpId' in op))
110
+ return [];
111
+ const { matchUpId } = op;
112
+ const unplaced = !resulted.has(matchUpId) && (removed.has(matchUpId) || unbyed.has(matchUpId));
113
+ return !settledResults.has(matchUpId) && (unplaced || unevented.has(matchUpId)) ? [matchUpId] : [];
114
+ }));
115
+ const structures = new Set(touchedStructures(ops).filter((structureId) => !eventedPlacement(ops, structureId)));
116
+ return { matchUps, structures };
117
+ }
118
+ const placement = (op) => op.op === 'assignPosition' || op.op === 'assignBye';
119
+ const touchedStructures = (ops) => [
120
+ ...new Set(ops.flatMap((op) => (placement(op) || op.op === 'withdrawBye' ? [op.structureId] : []))),
121
+ ];
122
+ const eventedPlacement = (ops, structureId) => ops.some((op) => placement(op) && op.structureId === structureId && !(op.op === 'assignBye' && op.announcesEvent === false));
106
123
  function dualTallyResult(ops) {
107
124
  const tally = ops.find((op) => op.op === 'setMatchUpResult' && op.dualTally);
108
- if (tally?.op !== 'setMatchUpResult')
125
+ if (tally?.op !== 'setMatchUpResult' || tally.dualTally?.unreturned)
109
126
  return {};
110
127
  return {
111
128
  tieMatchUpResult: {
@@ -117,9 +134,7 @@ function dualTallyResult(ops) {
117
134
  };
118
135
  }
119
136
  function announceAssignments({ drawDefinition, tournamentId, event, ops, }) {
120
- const placement = (op) => op.op === 'assignPosition' || op.op === 'assignBye';
121
- const touched = [...new Set(ops.flatMap((op) => (placement(op) || op.op === 'withdrawBye' ? [op.structureId] : [])))];
122
- for (const structureId of touched) {
137
+ for (const structureId of touchedStructures(ops)) {
123
138
  const { structure } = findStructure({ drawDefinition, structureId });
124
139
  if (!structure)
125
140
  continue;
@@ -128,11 +143,22 @@ function announceAssignments({ drawDefinition, tournamentId, event, ops, }) {
128
143
  modifyPositionAssignmentsNotice({ drawDefinition, structure, tournamentId: undefined, event: undefined });
129
144
  continue;
130
145
  }
131
- const evented = ops.some((op) => placement(op) && op.structureId === structureId && !(op.op === 'assignBye' && op.announcesEvent === false));
132
- const noticeEvent = evented ? event : undefined;
146
+ const noticeEvent = eventedPlacement(ops, structureId) ? event : undefined;
133
147
  modifyPositionAssignmentsNotice({ drawDefinition, tournamentId, structure, event: noticeEvent });
134
148
  }
135
149
  }
150
+ function withdrawnByeNotices(ops) {
151
+ const unbyed = new Map();
152
+ for (const op of ops) {
153
+ if (op.op === 'clearMatchUpBye')
154
+ unbyed.set(op.matchUpId, op.drawPosition);
155
+ if (op.op === 'setMatchUpDrawPositions' && op.withdrawnByePosition)
156
+ unbyed.set(op.matchUpId, op.withdrawnByePosition);
157
+ if (op.op === 'setMatchUpDrawPositions' && op.advancesThroughBye)
158
+ unbyed.delete(op.matchUpId);
159
+ }
160
+ return unbyed;
161
+ }
136
162
  function noticeContext(matchUpId, removedPosition, unbyedPosition, written) {
137
163
  if (removedPosition)
138
164
  return `removeSubsequentDrawPosition-${removedPosition}`;
@@ -141,11 +167,13 @@ function noticeContext(matchUpId, removedPosition, unbyedPosition, written) {
141
167
  return matchUpContext(matchUpId, written);
142
168
  }
143
169
  function matchUpContext(matchUpId, written) {
144
- const { resulted, byes, recoded, exchanged, relayed, advanced } = written;
170
+ const { resulted, byes, recoded, exchanged, relayed, advanced, released } = written;
145
171
  if (resulted.has(matchUpId))
146
172
  return 'modifyMatchUpScore';
147
173
  if (advanced.has(matchUpId) && !byes.has(matchUpId))
148
174
  return 'advanceWinner';
175
+ if (released.has(matchUpId))
176
+ return 'releaseAdvancedDrawPosition';
149
177
  if (relayed.has(matchUpId))
150
178
  return 'progressExitStatus';
151
179
  if (recoded.has(matchUpId) && byes.has(matchUpId))
@@ -156,5 +184,24 @@ function matchUpContext(matchUpId, written) {
156
184
  return 'swapWinnerLoser';
157
185
  return byes.has(matchUpId) ? 'setMatchUpStatusBye' : 'assignMatchUpDrawPosition';
158
186
  }
187
+ function namedWriters(ops) {
188
+ const settled = new Map();
189
+ const lineUpUnevented = new Set();
190
+ for (const op of ops) {
191
+ if (op.op === 'setSideLineUp') {
192
+ settled.set(op.matchUpId, op.announcedAs);
193
+ if (op.announcesEvent === false)
194
+ lineUpUnevented.add(op.matchUpId);
195
+ }
196
+ else if (op.op === 'setMatchUpResult') {
197
+ if (op.announcedAs)
198
+ settled.set(op.matchUpId, op.announcedAs);
199
+ else
200
+ settled.delete(op.matchUpId);
201
+ lineUpUnevented.delete(op.matchUpId);
202
+ }
203
+ }
204
+ return { settled, lineUpUnevented };
205
+ }
159
206
 
160
- export { applyOwnedPlan };
207
+ export { applyOwnedPlan, eventlessNotices };
@@ -1,12 +1,14 @@
1
1
  import { isExit, isDoubleExit, isAnyExit } from '../../../validators/isExit.mjs';
2
2
  import { FIRST_MATCHUP } from '../../../constants/drawDefinitionConstants.mjs';
3
- import { DOUBLE_DEFAULT, DEFAULTED, WALKOVER, BYE, TO_BE_PLAYED, DEAD_RUBBER, DOUBLE_WALKOVER, RETIRED } from '../../../constants/matchUpStatusValues.mjs';
3
+ import { DOUBLE_DEFAULT, DEFAULTED, WALKOVER, TO_BE_PLAYED, BYE, DEAD_RUBBER, DOUBLE_WALKOVER, RETIRED } from '../../../constants/matchUpStatusValues.mjs';
4
4
 
5
5
  function planDirection(request, view, route) {
6
6
  if (route === 'double-exit' || route === 'completed-to-double-exit')
7
7
  return planProducedExit(request, view);
8
8
  if (route === 'swap')
9
9
  return planSwap(request, view);
10
+ if (route === 'apply-values')
11
+ return planRelabelled(request, view);
10
12
  if (route !== 'winner')
11
13
  return undefined;
12
14
  if (view.line || view.matchUpTieId || view.draw.isAdHoc || view.targets.luckyPreFeed)
@@ -75,12 +77,23 @@ function carriedExit(request, view) {
75
77
  return undefined;
76
78
  if (isDoubleExit(view.targets.loserMatchUpStatus))
77
79
  return undefined;
78
- if (isRelabel(request, view) && (view.targets.loserMatchUpHasResult || view.targets.loserMatchUpStatus === BYE))
80
+ if (isRelabel(request, view) &&
81
+ !view.targets.loserMatchUpCarryHeld &&
82
+ (view.targets.loserMatchUpHasResult || view.targets.loserMatchUpStatus === BYE))
79
83
  return undefined;
80
84
  if (view.targets.loserMatchUpId && view.targets.loserMatchUpId === view.targets.winnerMatchUpId)
81
85
  return undefined;
82
86
  return isExit(matchUpStatus) && matchUpStatus !== RETIRED ? matchUpStatus : WALKOVER;
83
87
  }
88
+ function planRelabelled(request, view) {
89
+ if (!isRelabel(request, view) || view.line || view.matchUpTieId || view.isTeam)
90
+ return undefined;
91
+ const winningSide = request.winningSide;
92
+ if (winningSide !== 1 && winningSide !== 2)
93
+ return undefined;
94
+ const loser = planLoser(request, view, winningSide === 1 ? 2 : 1);
95
+ return loser ? { loser } : undefined;
96
+ }
84
97
  function isRelabel(request, view) {
85
98
  return !!view.existing.winningSide && view.existing.winningSide === request.winningSide;
86
99
  }
@@ -91,7 +104,7 @@ function convergence(statuses) {
91
104
  }
92
105
  function planProducedExit(request, view) {
93
106
  const { winner, source, winnerMatchUpId } = view.targets;
94
- if (!winner || !winnerMatchUpId || view.line || view.matchUpTieId || view.isTeam)
107
+ if (!winner || !winnerMatchUpId || view.line || view.matchUpTieId)
95
108
  return undefined;
96
109
  if (isDoubleExit(winner.matchUpStatus))
97
110
  return undefined;
@@ -119,8 +132,12 @@ function planSwap(request, view) {
119
132
  const plan = planDirection(request, swapped, 'winner');
120
133
  if (!plan?.loser)
121
134
  return plan;
122
- const { exit: _exit, converged: _converged, carriedPast: _carriedPast, ...loser } = plan.loser;
123
- return { ...plan, loser };
135
+ const { exit, converged: _converged, carriedPast: _carriedPast, ...loser } = plan.loser;
136
+ const { targets } = view;
137
+ const clean = targets.loserMatchUpStatus === TO_BE_PLAYED &&
138
+ !targets.loserMatchUpCarriesExit &&
139
+ !targets.loserTargetSeat?.opponentBye;
140
+ return { ...plan, loser: exit && (clean || targets.loserMatchUpCarryHeld) ? { ...loser, exit } : loser };
124
141
  }
125
142
  function planDecider(view, winningSide) {
126
143
  const { winnerMatchUpId, loserMatchUpId, winner, source, sideParticipantIds, priorLosses } = view.targets;
@@ -3,10 +3,12 @@ import { setSideExitProvenance, mergeSideExitProvenance } from '../matchUpStatus
3
3
  import { setMatchUpDrawPositions } from '../drawPositions/setMatchUpDrawPositions.mjs';
4
4
  import { matchUpsOf, structuresOf, positionAssignmentsOf } from '../../../acquire/structureMembers.mjs';
5
5
  import { exchangeMatchUpPositions } from '../drawPositions/swapWinnerLoser.mjs';
6
+ import { setFirstClassOrExtension } from '../../extensions/setFirstClassOrExtension.mjs';
6
7
  import { matchUpIsScored } from '../matchUpStatus/reconcileScoredTimes.mjs';
7
8
  import { getCapturedStamps } from '../../../global/state/globalState.mjs';
8
9
  import { nowIso } from '../../../tools/clock.mjs';
9
10
  import { TO_BE_PLAYED, BYE } from '../../../constants/matchUpStatusValues.mjs';
11
+ import { DISABLE_AUTO_CALC } from '../../../constants/extensionConstants.mjs';
10
12
 
11
13
  function nextStamp(previous, now = nowIso()) {
12
14
  if (!previous || previous < now)
@@ -41,6 +43,13 @@ function setMatchUpResult(matchUp, op) {
41
43
  matchUp.sides = structuredClone(op.dualTally.sides);
42
44
  if (op.ensuredSides)
43
45
  matchUp.sides = structuredClone(op.ensuredSides);
46
+ if (op.disableAutoCalc !== undefined)
47
+ setFirstClassOrExtension({
48
+ element: matchUp,
49
+ attribute: 'disableAutoCalc',
50
+ name: DISABLE_AUTO_CALC,
51
+ value: op.disableAutoCalc,
52
+ });
44
53
  if (op.dualTally?.tieFormat)
45
54
  matchUp.tieFormat = structuredClone(op.dualTally.tieFormat);
46
55
  matchUp.matchUpStatus = op.matchUpStatus;
@@ -110,8 +110,9 @@ function createWorkingView({ inContextDrawMatchUps: base, structural, tournament
110
110
  const applied = applyOutcomeOps(workingDraw, ops);
111
111
  if (applied.error)
112
112
  return applied;
113
+ const seatOps = new Set(['assignPosition', 'clearPosition', 'relabelPosition', 'assignBye', 'withdrawBye']);
113
114
  for (const op of ops) {
114
- if (op.op !== 'assignPosition' && op.op !== 'clearPosition' && op.op !== 'relabelPosition')
115
+ if (!seatOps.has(op.op) || !('drawPosition' in op) || !('structureId' in op))
115
116
  continue;
116
117
  for (const matchUp of matchUpsOf(structureHolding(op.structureId)) ?? [])
117
118
  if (matchUp.drawPositions?.includes(op.drawPosition))