Tagging asserts in preparation for a release.

Commands used:

```shell
npm run policy-check:asserts
```

Then in the tree project:

```shell
npm run format
```
This commit is contained in:
Tyler Butler 2023-01-25 09:36:42 -08:00 коммит произвёл GitHub
Родитель b65220dcb7
Коммит f19c31a489
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 135 добавлений и 70 удалений

Просмотреть файл

@ -121,10 +121,13 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
// We want the floor of the result, which can computed using a bitwise shift assuming the depth is less than 2^31, which seems safe.
// eslint-disable-next-line no-bitwise
const halfHeight = (this.siblingStack.length + 1) >> 1;
assert(this.indexOfChunkStack.length === halfHeight, "unexpected indexOfChunkStack");
assert(
this.indexOfChunkStack.length === halfHeight,
0x51c /* unexpected indexOfChunkStack */,
);
assert(
this.indexWithinChunkStack.length === halfHeight,
"unexpected indexWithinChunkStack",
0x51d /* unexpected indexWithinChunkStack */,
);
return this.siblingStack.length % 2 === 0
? CursorLocationType.Fields
@ -132,18 +135,18 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
}
public getFieldKey(): FieldKey {
assert(this.mode === CursorLocationType.Fields, "must be in fields mode");
assert(this.mode === CursorLocationType.Fields, 0x51e /* must be in fields mode */);
return this.siblings[this.index] as FieldKey;
}
private getStackedFieldKey(height: number): FieldKey {
assert(height % 2 === 0, "must field height");
assert(height % 2 === 0, 0x51f /* must field height */);
return this.siblingStack[height][this.indexStack[height]] as FieldKey;
}
private getStackedNodeIndex(height: number): number {
assert(height % 2 === 1, "must be node height");
assert(height >= 0, "must not be above root");
assert(height % 2 === 1, 0x520 /* must be node height */);
assert(height >= 0, 0x521 /* must not be above root */);
return this.indexStack[height];
}
@ -153,22 +156,22 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
}
public getFieldLength(): number {
assert(this.mode === CursorLocationType.Fields, "must be in fields mode");
assert(this.mode === CursorLocationType.Fields, 0x522 /* must be in fields mode */);
return this.getField().length;
}
public enterNode(index: number): void {
const found = this.firstNode() && this.seekNodes(index);
assert(found, "child must exist at index");
assert(found, 0x523 /* child must exist at index */);
}
public getPath(): UpPath | undefined {
assert(this.mode === CursorLocationType.Nodes, "must be in nodes mode");
assert(this.mode === CursorLocationType.Nodes, 0x524 /* must be in nodes mode */);
return this.getOffsetPath(0);
}
public getFieldPath(): FieldUpPath {
assert(this.mode === CursorLocationType.Fields, "must be in fields mode");
assert(this.mode === CursorLocationType.Fields, 0x525 /* must be in fields mode */);
return {
field: this.getFieldKey(),
parent: this.getOffsetPath(1),
@ -181,8 +184,8 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
return undefined; // At root
}
assert(length > 0, "invalid offset to above root");
assert(length % 2 === 1, "offset path must point to node not field");
assert(length > 0, 0x526 /* invalid offset to above root */);
assert(length % 2 === 1, 0x527 /* offset path must point to node not field */);
// Perf Note:
// This is O(depth) in tree.
@ -212,7 +215,7 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
}
public enterField(key: FieldKey): void {
assert(this.mode === CursorLocationType.Nodes, "must be in nodes mode");
assert(this.mode === CursorLocationType.Nodes, 0x528 /* must be in nodes mode */);
this.siblingStack.push(this.siblings);
this.indexStack.push(this.index);
@ -248,8 +251,11 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
}
public seekNodes(offset: number): boolean {
assert(this.mode === CursorLocationType.Nodes, "can only seekNodes when in Nodes");
assert(this.indexOfChunk < this.siblings.length, "out of bounds indexOfChunk");
assert(
this.mode === CursorLocationType.Nodes,
0x529 /* can only seekNodes when in Nodes */,
);
assert(this.indexOfChunk < this.siblings.length, 0x52a /* out of bounds indexOfChunk */);
this.indexWithinChunk += offset;
if (offset >= 0) {
@ -261,7 +267,10 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
this.exitNode();
return false;
}
assert(this.indexOfChunk < this.siblings.length, "out of bounds indexOfChunk");
assert(
this.indexOfChunk < this.siblings.length,
0x52b /* out of bounds indexOfChunk */,
);
}
} else {
const chunks = this.siblings as TreeChunk[];
@ -296,7 +305,7 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
}
public nextNode(): boolean {
assert(this.mode === CursorLocationType.Nodes, "can only nextNode when in Nodes");
assert(this.mode === CursorLocationType.Nodes, 0x52c /* can only nextNode when in Nodes */);
this.indexWithinChunk++;
if (
this.indexWithinChunk ===
@ -316,7 +325,7 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
public exitField(): void {
assert(
this.mode === CursorLocationType.Fields,
"can only navigate up from field when in field",
0x52d /* can only navigate up from field when in field */,
);
this.siblings = this.siblingStack.pop() ?? fail("Unexpected siblingStack.length");
this.index = this.indexStack.pop() ?? fail("Unexpected indexStack.length");
@ -325,7 +334,7 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
public exitNode(): void {
assert(
this.mode === CursorLocationType.Nodes,
"can only navigate up from node when in node",
0x52e /* can only navigate up from node when in node */,
);
this.siblings = this.siblingStack.pop() ?? fail("Unexpected siblingStack.length");
this.index = this.indexStack.pop() ?? fail("Unexpected indexStack.length");
@ -336,7 +345,7 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
}
public getNode(): BasicChunk {
assert(this.mode === CursorLocationType.Nodes, "can only get node when in node");
assert(this.mode === CursorLocationType.Nodes, 0x52f /* can only get node when in node */);
return (this.siblings as TreeChunk[])[this.index] as BasicChunk;
}
@ -344,7 +353,10 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
if (this.siblingStack.length === 0) {
return this.root;
}
assert(this.mode === CursorLocationType.Fields, "can only get field when in fields");
assert(
this.mode === CursorLocationType.Fields,
0x530 /* can only get field when in fields */,
);
const parent = this.getStackedNode(this.indexStack.length - 1);
const key: FieldKey = this.getFieldKey();
const field = parent.fields.get(key) ?? [];
@ -360,7 +372,10 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
}
public get fieldIndex(): number {
assert(this.mode === CursorLocationType.Nodes, "can only node's index when in node");
assert(
this.mode === CursorLocationType.Nodes,
0x531 /* can only node's index when in node */,
);
return this.index;
}

Просмотреть файл

@ -90,7 +90,7 @@ class ChunkedForest extends SimpleDependee implements IEditableForest {
let mutableChunk: BasicChunk | undefined = this.roots;
const getParent = () => {
assert(mutableChunkStack.length > 0, "invalid access to root's parent");
assert(mutableChunkStack.length > 0, 0x532 /* invalid access to root's parent */);
return mutableChunkStack[mutableChunkStack.length - 1];
};
@ -141,14 +141,14 @@ class ChunkedForest extends SimpleDependee implements IEditableForest {
const toAttach = moves.get(id) ?? fail("move in without move out");
moves.delete(id);
const countMoved = moveIn(index, toAttach);
assert(countMoved === count, "counts must match");
assert(countMoved === count, 0x533 /* counts must match */);
},
onSetValue: (value: Value): void => {
assert(mutableChunk !== undefined, "should be in node");
assert(mutableChunk !== undefined, 0x534 /* should be in node */);
mutableChunk.value = value;
},
enterNode: (index: number): void => {
assert(mutableChunk === undefined, "should be in field");
assert(mutableChunk === undefined, 0x535 /* should be in field */);
const parent = getParent();
const chunks =
parent.mutableChunk.fields.get(parent.key) ?? fail("missing edited field");
@ -162,7 +162,10 @@ class ChunkedForest extends SimpleDependee implements IEditableForest {
}
}
const found = chunks[indexOfChunk];
assert(found instanceof BasicChunk, "mixed chunk support not yet implemented");
assert(
found instanceof BasicChunk,
0x536 /* mixed chunk support not yet implemented */,
);
if (found.isShared()) {
mutableChunk = chunks[indexOfChunk] = found.clone();
found.referenceRemoved();
@ -171,17 +174,17 @@ class ChunkedForest extends SimpleDependee implements IEditableForest {
}
},
exitNode: (index: number): void => {
assert(mutableChunk !== undefined, "should be in node");
assert(mutableChunk !== undefined, 0x537 /* should be in node */);
mutableChunk = undefined;
},
enterField: (key: FieldKey): void => {
assert(mutableChunk !== undefined, "should be in node");
assert(mutableChunk !== undefined, 0x538 /* should be in node */);
mutableChunkStack.push({ key, mutableChunk });
mutableChunk = undefined;
},
exitField: (key: FieldKey): void => {
const top = mutableChunkStack.pop() ?? fail("should not be at root");
assert(mutableChunk === undefined, "should be in field");
assert(mutableChunk === undefined, 0x539 /* should be in field */);
mutableChunk = top.mutableChunk;
},
};
@ -195,7 +198,7 @@ class ChunkedForest extends SimpleDependee implements IEditableForest {
const field: DetachedField = brand(String(this.nextDetachedFieldIdentifier));
assert(
!this.roots.fields.has(detachedFieldAsKey(field)),
"new field must not already exist",
0x53a /* new field must not already exist */,
);
this.nextDetachedFieldIdentifier += 1;
return field;
@ -235,7 +238,7 @@ class ChunkedForest extends SimpleDependee implements IEditableForest {
): TreeNavigationResult {
assert(
cursorToMove instanceof Cursor,
"ChunkedForest must only be given its own Cursor type",
0x53b /* ChunkedForest must only be given its own Cursor type */,
);
if (destination.parent === undefined) {
cursorToMove.setToDetachedSequence(destination.fieldKey);
@ -258,9 +261,12 @@ class ChunkedForest extends SimpleDependee implements IEditableForest {
moveCursorToPath(destination: UpPath | undefined, cursorToMove: ITreeSubscriptionCursor): void {
assert(
cursorToMove instanceof Cursor,
"ChunkedForest must only be given its own Cursor type",
0x53c /* ChunkedForest must only be given its own Cursor type */,
);
assert(
cursorToMove.forest === this,
0x53d /* ChunkedForest must only be given its own Cursor */,
);
assert(cursorToMove.forest === this, "ChunkedForest must only be given its own Cursor");
const indexStack: number[] = [];
const keyStack: FieldKey[] = [];

Просмотреть файл

@ -295,7 +295,10 @@ class Cursor extends SynchronousCursor implements ITreeCursorSynchronous {
*/
private nodeInfo(requiredMode: CursorLocationType): NodePositionInfo {
assert(this.mode === requiredMode, 0x4c8 /* tried to access cursor when in wrong mode */);
assert(this.nodePositionInfo !== undefined, "can not access nodeInfo in root field");
assert(
this.nodePositionInfo !== undefined,
0x53e /* can not access nodeInfo in root field */,
);
return this.nodePositionInfo;
}
@ -323,7 +326,7 @@ class Cursor extends SynchronousCursor implements ITreeCursorSynchronous {
getFieldLength(): number {
assert(
this.mode === CursorLocationType.Fields,
"tried to access cursor when in wrong mode",
0x53f /* tried to access cursor when in wrong mode */,
);
if (this.nodePositionInfo === undefined) {
return this.shape.topLevelLength;
@ -338,7 +341,7 @@ class Cursor extends SynchronousCursor implements ITreeCursorSynchronous {
firstNode(): boolean {
assert(
this.mode === CursorLocationType.Fields,
"tried to access cursor when in wrong mode",
0x540 /* tried to access cursor when in wrong mode */,
);
if (this.nodePositionInfo === undefined) {
@ -353,13 +356,13 @@ class Cursor extends SynchronousCursor implements ITreeCursorSynchronous {
enterNode(childIndex: number): void {
assert(
this.mode === CursorLocationType.Fields,
"tried to access cursor when in wrong mode",
0x541 /* tried to access cursor when in wrong mode */,
);
assert(childIndex >= 0, 0x4ca /* index must be positive */);
if (this.nodePositionInfo === undefined) {
assert(
childIndex < this.shape.topLevelLength,
"index must not be past the end of the field",
0x542 /* index must not be past the end of the field */,
);
this.enterRootNodeInner(childIndex);
} else {
@ -392,7 +395,7 @@ class Cursor extends SynchronousCursor implements ITreeCursorSynchronous {
this.mode = CursorLocationType.Nodes;
// 1 for the "undefined" at the beginning of the positions array, then stride by top level tree shape.
this.moveToPosition(1 + childIndex * this.shape.treeShape.positions.length);
assert(this.fieldIndex === childIndex, "should be at selected child");
assert(this.fieldIndex === childIndex, 0x543 /* should be at selected child */);
}
getFieldPath(): FieldUpPath {

Просмотреть файл

@ -224,7 +224,7 @@ function applyMoveEffectsToDest<T>(
const effect = getMoveEffect(effects, MoveEnd.Dest, mark.revision ?? revision, mark.id);
const result: Mark<T>[] = [];
assert(effect.modifyAfter === undefined, "Cannot modify move destination");
assert(effect.modifyAfter === undefined, 0x544 /* Cannot modify move destination */);
if (effect.mark !== undefined) {
result.push(effect.mark);
} else {
@ -251,7 +251,7 @@ function applyMoveEffectsToDest<T>(
mark.revision ?? revision,
effect.child,
);
assert(childEffect.count !== undefined, "Child effects should have size");
assert(childEffect.count !== undefined, 0x545 /* Child effects should have size */);
const newMark: Mark<T> = {
...mark,
@ -260,7 +260,10 @@ function applyMoveEffectsToDest<T>(
};
if (mark.type === "ReturnTo" && mark.detachIndex !== undefined) {
assert(effect.count !== undefined, "Should define count when splitting a mark");
assert(
effect.count !== undefined,
0x546 /* Should define count when splitting a mark */,
);
(newMark as ReturnTo).detachIndex = mark.detachIndex + effect.count;
}
@ -293,7 +296,7 @@ function applyMoveEffectsToSource<T>(
if (effect.modifyAfter !== undefined) {
assert(
composeChildren !== undefined,
"Must provide a change composer if modifying moves",
0x547 /* Must provide a change composer if modifying moves */,
);
const changes = composeChildren(newMark.changes, effect.modifyAfter);
if (changes !== undefined) {
@ -303,7 +306,10 @@ function applyMoveEffectsToSource<T>(
}
}
if (effect.pairedMarkStatus !== undefined) {
assert(newMark.type === "ReturnFrom", "TODO: support updating MoveOut.isSrcConflicted");
assert(
newMark.type === "ReturnFrom",
0x548 /* TODO: support updating MoveOut.isSrcConflicted */,
);
if (effect.pairedMarkStatus === PairedMarkUpdate.Deactivated) {
newMark.isDstConflicted = true;
} else {
@ -320,14 +326,17 @@ function applyMoveEffectsToSource<T>(
mark.revision ?? revision,
effect.child,
);
assert(childEffect.count !== undefined, "Child effects should have size");
assert(childEffect.count !== undefined, 0x549 /* Child effects should have size */);
const newMark: MoveOut<T> | ReturnFrom<T> = {
...mark,
id: effect.child,
count: childEffect.count,
};
if (mark.type === "ReturnFrom" && mark.detachIndex !== undefined) {
assert(effect.count !== undefined, "Should define count when splitting a mark");
assert(
effect.count !== undefined,
0x54a /* Should define count when splitting a mark */,
);
(newMark as ReturnFrom).detachIndex = mark.detachIndex + effect.count;
}
result.push(

Просмотреть файл

@ -457,7 +457,7 @@ function tryMergeMoves(
const leftEffect = getOrAddEffect(moveEffects, end, rev, left.id);
if (leftEffect.mergeRight === right.id) {
const rightEffect = getMoveEffect(moveEffects, end, rev, right.id);
assert(rightEffect.mergeLeft === left.id, "Inconsistent merge info");
assert(rightEffect.mergeLeft === left.id, 0x54b /* Inconsistent merge info */);
const nextId = rightEffect.mergeRight;
if (nextId !== undefined) {
makeMergeable(moveEffects, end, rev, left.id, nextId);

Просмотреть файл

@ -345,7 +345,7 @@ export class SessionIdNormalizer<TRangeObject> {
}
assert(
unalignedLocalCount > 0,
"Final ID block should not be registered without an existing local range.",
0x51b /* Final ID block should not be registered without an existing local range. */,
);
const lastFinal = (firstFinalInBlock +
Math.min(unalignedLocalCount, count) -

Просмотреть файл

@ -836,7 +836,7 @@ export class Container extends EventEmitterWithErrorHandling<IContainerEvents> i
private _disposed = false;
private disposeCore(error?: ICriticalContainerError) {
assert(!this._disposed, "Container already disposed");
assert(!this._disposed, 0x54c /* Container already disposed */);
this._disposed = true;
try {

Просмотреть файл

@ -848,7 +848,6 @@ export const shortCodeMap = {
"0x440": "Cursor must be current to be used",
"0x441": "Cursor must be current to be used",
"0x443": "Requested offset should be valid",
"0x444": "Collection should have at least one entry",
"0x445": "Invalid attribution summary blob provided",
"0x446": "Expected either all segments or no segments to have attribution information.",
"0x447": "can only append text segment",
@ -867,7 +866,7 @@ export const shortCodeMap = {
"0x456": "Index must be less than or equal to length.",
"0x457": "Index must be less than length.",
"0x458": "Count must be non-negative.",
"0x45a": "transactionCheckout` is required to edit the EditableTre",
"0x45a": "`transactionCheckout` is required to edit the EditableTree",
"0x45f": "Cursor must be current to be used",
"0x460": "Cursor must be current to be used",
"0x466": "entryPoint for AgentSchedulerRuntime should have been initialized by now",
@ -908,7 +907,6 @@ export const shortCodeMap = {
"0x48a": "Cannot finalize an empty range.",
"0x48b": "The number of allocated final IDs must not exceed the JS maximum safe integer.",
"0x48c": "Cluster already exists for session but there is no finalized local ID",
"0x48d": "The number of unfinalized locals should only be positive",
"0x48e": "The number of allocated final IDs must not exceed the JS maximum safe integer.",
"0x48f": "Override IDs must be in sorted order.",
"0x490": "Ranges finalized out of order.",
@ -965,7 +963,6 @@ export const shortCodeMap = {
"0x4c4": "Negative ref count",
"0x4c5": "no duplicate keys",
"0x4c6": "topLevelLength must be greater than 0",
"0x4c7": "index must not be greater than the number of nodes",
"0x4c8": "tried to access cursor when in wrong mode",
"0x4c9": "exitField when in wrong mode",
"0x4ca": "index must be positive",
@ -995,20 +992,6 @@ export const shortCodeMap = {
"0x4e2": "Unexpected end of mark queue",
"0x4e3": "Can only split sized marks on input",
"0x4e4": "Should only dequeue output if the next mark has output length > 0",
"0x4e5": "There should be an entry in splitIdToOrigId for this ID",
"0x4e6": "There should be an entry in splitIdToOrigId for this ID",
"0x4e7": "Move dest already replaced",
"0x4e8": "This MoveId cannot be replaced",
"0x4e9": "Move source already replaced",
"0x4ea": "Move source already been modified",
"0x4eb": "Move source already replaced",
"0x4ec": "This MoveId cannot be replaced",
"0x4ed": "Cannot remap ID which has already been remapped",
"0x4ee": "Cannot modify move destination",
"0x4ef": "Must provide a change composer if modifying moves",
"0x4f0": "TODO: support updating MoveOut.isSrcConflicted",
"0x4f1": "Only ReturnFrom marks can have their detachBy field set",
"0x4f2": "Conflicted ReturnFrom should have a detachIndex",
"0x4f3": "Unable to keep track of the base input offset in composite changeset",
"0x4f4": "Non-empty queue should return at least one mark",
"0x4f5": "A new attach cannot be at the same position as another mark",
@ -1022,7 +1005,6 @@ export const shortCodeMap = {
"0x4fd": "Invalid revive mark overlap",
"0x4fe": "Only a skip-like reattach can overlap with a ReturnFrom",
"0x4ff": "Only a skip-like reattach can overlap with a ReturnFrom",
"0x500": "Non-empty RebaseQueue should return at least one mark",
"0x501": "Unknown mark type with net-zero node count change",
"0x502": "Compose base mark should carry revision info",
"0x503": "Compose base mark should carry revision info",
@ -1048,5 +1030,55 @@ export const shortCodeMap = {
"0x517": "Batch needs to be compressed",
"0x518": "First message in the batch needs to be chunkable",
"0x519": "We don't support old loaders",
"0x51a": "We should have something to chunk"
"0x51a": "We should have something to chunk",
"0x51b": "Final ID block should not be registered without an existing local range.",
"0x51c": "unexpected indexOfChunkStack",
"0x51d": "unexpected indexWithinChunkStack",
"0x51e": "must be in fields mode",
"0x51f": "must field height",
"0x520": "must be node height",
"0x521": "must not be above root",
"0x522": "must be in fields mode",
"0x523": "child must exist at index",
"0x524": "must be in nodes mode",
"0x525": "must be in fields mode",
"0x526": "invalid offset to above root",
"0x527": "offset path must point to node not field",
"0x528": "must be in nodes mode",
"0x529": "can only seekNodes when in Nodes",
"0x52a": "out of bounds indexOfChunk",
"0x52b": "out of bounds indexOfChunk",
"0x52c": "can only nextNode when in Nodes",
"0x52d": "can only navigate up from field when in field",
"0x52e": "can only navigate up from node when in node",
"0x52f": "can only get node when in node",
"0x530": "can only get field when in fields",
"0x531": "can only node's index when in node",
"0x532": "invalid access to root's parent",
"0x533": "counts must match",
"0x534": "should be in node",
"0x535": "should be in field",
"0x536": "mixed chunk support not yet implemented",
"0x537": "should be in node",
"0x538": "should be in node",
"0x539": "should be in field",
"0x53a": "new field must not already exist",
"0x53b": "ChunkedForest must only be given its own Cursor type",
"0x53c": "ChunkedForest must only be given its own Cursor type",
"0x53d": "ChunkedForest must only be given its own Cursor",
"0x53e": "can not access nodeInfo in root field",
"0x53f": "tried to access cursor when in wrong mode",
"0x540": "tried to access cursor when in wrong mode",
"0x541": "tried to access cursor when in wrong mode",
"0x542": "index must not be past the end of the field",
"0x543": "should be at selected child",
"0x544": "Cannot modify move destination",
"0x545": "Child effects should have size",
"0x546": "Should define count when splitting a mark",
"0x547": "Must provide a change composer if modifying moves",
"0x548": "TODO: support updating MoveOut.isSrcConflicted",
"0x549": "Child effects should have size",
"0x54a": "Should define count when splitting a mark",
"0x54b": "Inconsistent merge info",
"0x54c": "Container already disposed"
};