Skip to content

Commit

Permalink
Tag asserts (#15203)
Browse files Browse the repository at this point in the history
## Description

`pnpm exec flub release -g client` and `pnpm run prettier:fix`

Includes fixes for experimental/dds/tree so its tests for asserts keep
working after the tagging.
  • Loading branch information
CraigMacomber authored Apr 21, 2023
1 parent 7796557 commit 1f13911
Show file tree
Hide file tree
Showing 45 changed files with 584 additions and 275 deletions.
2 changes: 1 addition & 1 deletion api-report/test-runtime-utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ export class MockStorage implements IChannelStorageService {
}

// @public
export function validateAssertionError(error: Error, expectedErrorMsg: string): boolean;
export function validateAssertionError(error: Error, expectedErrorMsg: string | RegExp): boolean;

// (No @packageDocumentation comment for this package)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class SquaresApp {
(property) => {
assert(
property instanceof ContainerProperty,
"Property should always be a ContainerProperty.",
0x5eb /* Property should always be a ContainerProperty. */,
);

const values = property.getValues<any>();
Expand Down
23 changes: 13 additions & 10 deletions experimental/dds/attributable-map/src/mapKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class AttributableMapKernel {

assert(
!attribution || attribution.type !== "local",
"The attribution for summarization should not be local type",
0x5ec /* The attribution for summarization should not be local type */,
);

serializableMapData[key] = localValue.makeSerialized(
Expand Down Expand Up @@ -690,7 +690,7 @@ export class AttributableMapKernel {
localOpMetadata !== undefined &&
isMapKeyLocalOpMetadata(localOpMetadata) &&
localOpMetadata.pendingMessageId < this.pendingClearMessageIds[0],
"Received out of order op when there is an unackd clear message",
0x5ed /* Received out of order op when there is an unackd clear message */,
);
}
// If we have an unack'd clear, we can ignore all ops.
Expand All @@ -704,13 +704,13 @@ export class AttributableMapKernel {
if (local) {
assert(
localOpMetadata !== undefined && isMapKeyLocalOpMetadata(localOpMetadata),
"pendingMessageId is missing from the local client's operation",
0x5ee /* pendingMessageId is missing from the local client's operation */,
);
const pendingMessageIds = this.pendingKeys.get(op.key);
assert(
pendingMessageIds !== undefined &&
pendingMessageIds[0] === localOpMetadata.pendingMessageId,
"Unexpected pending message received",
0x5ef /* Unexpected pending message received */,
);
pendingMessageIds.shift();
if (pendingMessageIds.length === 0) {
Expand Down Expand Up @@ -741,12 +741,12 @@ export class AttributableMapKernel {
if (local) {
assert(
isClearLocalOpMetadata(localOpMetadata),
"pendingMessageId is missing from the local client's clear operation",
0x5f0 /* pendingMessageId is missing from the local client's clear operation */,
);
const pendingClearMessageId = this.pendingClearMessageIds.shift();
assert(
pendingClearMessageId === localOpMetadata.pendingMessageId,
"pendingMessageId does not match",
0x5f1 /* pendingMessageId does not match */,
);
this.clearAllAttribution();
return;
Expand All @@ -761,13 +761,13 @@ export class AttributableMapKernel {
submit: (op: IMapClearOperation, localOpMetadata: IMapClearLocalOpMetadata) => {
assert(
isClearLocalOpMetadata(localOpMetadata),
"Invalid localOpMetadata for clear",
0x5f2 /* Invalid localOpMetadata for clear */,
);
// We don't reuse the metadata pendingMessageId but send a new one on each submit.
const pendingClearMessageId = this.pendingClearMessageIds.shift();
assert(
pendingClearMessageId === localOpMetadata.pendingMessageId,
"pendingMessageId does not match",
0x5f3 /* pendingMessageId does not match */,
);
this.submitMapClearMessage(op, localOpMetadata.previousMap);
},
Expand Down Expand Up @@ -874,14 +874,17 @@ export class AttributableMapKernel {
* @param localOpMetadata - Metadata from the previous submit
*/
private resubmitMapKeyMessage(op: IMapKeyOperation, localOpMetadata: MapLocalOpMetadata): void {
assert(isMapKeyLocalOpMetadata(localOpMetadata), "Invalid localOpMetadata in submit");
assert(
isMapKeyLocalOpMetadata(localOpMetadata),
0x5f4 /* Invalid localOpMetadata in submit */,
);

// clear the old pending message id
const pendingMessageIds = this.pendingKeys.get(op.key);
assert(
pendingMessageIds !== undefined &&
pendingMessageIds[0] === localOpMetadata.pendingMessageId,
"Unexpected pending message received",
0x5f5 /* Unexpected pending message received */,
);
pendingMessageIds.shift();
if (pendingMessageIds.length === 0) {
Expand Down
5 changes: 4 additions & 1 deletion experimental/dds/ot/ot/src/ot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ export abstract class SharedOT<TState, TOp> extends SharedObject {
protected abstract transform(input: TOp, transform: TOp): TOp;

protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {
assert(this.pendingOps.length === 0, "Summarizer must not have locally pending changes.");
assert(
this.pendingOps.length === 0,
0x5f6 /* Summarizer must not have locally pending changes. */,
);

return createSingleBlobSummary("header", serializer.stringify(this.global, this.handle));
}
Expand Down
2 changes: 1 addition & 1 deletion experimental/dds/sequence-deprecated/src/sparsematrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class PaddingSegment extends BaseSegment {
}

public append(segment: ISegment) {
assert(PaddingSegment.is(segment), "can only append padding segment");
assert(PaddingSegment.is(segment), 0x5f7 /* can only append padding segment */);
super.append(segment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('SharedTreeQuerier', () => {
}

function intNode(idContext: NodeIdContext, value: number): ChangeNode {
assert(value === Math.round(value), 'Not an int');
assert(value === Math.round(value), 0x5f8 /* Not an int */);
return {
definition: 'Int' as Definition,
identifier: idContext.generateNodeId(),
Expand Down Expand Up @@ -178,14 +178,14 @@ describe('SharedTreeQuerier', () => {
}

function getPizzas(query: Maybe<Query>): Pizza[] {
assert(query !== null && query !== undefined, 'Query returned null unexpectedly');
assert(query.pizzas !== null && query.pizzas !== undefined, 'Query returned no pizzas');
assert(query !== null && query !== undefined, 0x5f9 /* Query returned null unexpectedly */);
assert(query.pizzas !== null && query.pizzas !== undefined, 0x5fa /* Query returned no pizzas */);
return query.pizzas;
}

function getDrinks(query: Maybe<Query>): Drink[] {
assert(query !== null && query !== undefined, 'Query returned null unexpectedly');
assert(query.drinks !== null && query.drinks !== undefined, 'Query returned no pizzas');
assert(query !== null && query !== undefined, 0x5fb /* Query returned null unexpectedly */);
assert(query.drinks !== null && query.drinks !== undefined, 0x5fc /* Query returned no pizzas */);
return query.drinks;
}

Expand Down
2 changes: 1 addition & 1 deletion experimental/dds/tree-graphql/src/test/TestUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createTestQueryTree(nodeFactory: (idContext: NodeIdContext) => C
// Follow the graphql convention that the root type of a schema must of type 'Query'
// Traits are copied off of the Query node and applied to the root node
// This is simply to save space/complexity in the tree, rather than adding the query root node _under_ the `initialTree` root node
assert(treeNode.definition === 'Query', 'root node must be a Query node');
assert(treeNode.definition === 'Query', 0x5fd /* root node must be a Query node */);
for (const [label, trait] of Object.entries(treeNode.traits)) {
tree.applyEdit(
...Change.insertTree(
Expand Down
4 changes: 2 additions & 2 deletions experimental/dds/tree/src/ChangeTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ export const StableRange = {
if (start.referenceTrait && end.referenceTrait) {
assert(
start.referenceTrait.parent === end.referenceTrait.parent,
'StableRange must be constructed with endpoints from the same trait'
0x5fe /* StableRange must be constructed with endpoints from the same trait */
);
assert(
start.referenceTrait.label === end.referenceTrait.label,
'StableRange must be constructed with endpoints from the same trait'
0x5ff /* StableRange must be constructed with endpoints from the same trait */
);
}
return { start, end };
Expand Down
27 changes: 14 additions & 13 deletions experimental/dds/tree/src/Checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
* Changes accumulate in the edit via calls to `applyChanges()`.
*/
public openEdit(): void {
assert(this.currentEdit === undefined, 'An edit is already open.');
assert(this.currentEdit === undefined, 0x600 /* An edit is already open. */);
this.currentEdit = TransactionInternal.factory(this.latestCommittedView);
}

Expand All @@ -170,11 +170,12 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
*/
public closeEdit(): EditId {
const { currentEdit } = this;
assert(currentEdit !== undefined, 'An edit is not open.');
assert(currentEdit !== undefined, 0x601 /* An edit is not open. */);
this.currentEdit = undefined;
if (currentEdit.failure !== undefined) {
fail('Cannot close a transaction that has already failed. Use abortEdit instead.');
}
assert(
currentEdit.failure === undefined,
0x66d /* Cannot close a transaction that has already failed. Use abortEdit instead. */
);

const editingResult = currentEdit.close();
this.validateChangesApplied(editingResult);
Expand Down Expand Up @@ -258,7 +259,7 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
public applyChanges(changes: readonly Change[]): void;
public applyChanges(...changes: readonly Change[]): void;
public applyChanges(...changes: RestOrArray<Change>): void {
assert(this.currentEdit !== undefined, 'Changes must be applied as part of an ongoing edit.');
assert(this.currentEdit !== undefined, 0x602 /* Changes must be applied as part of an ongoing edit. */);
const changeArray = unwrapRestOrArray(changes);
const { status } = this.currentEdit.applyChanges(changeArray.map((c) => this.tree.internalizeChange(c)));
this.validateChangesApplied({ status, failure: this.currentEdit.failure });
Expand All @@ -273,7 +274,7 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
protected tryApplyChangesInternal(changes: readonly ChangeInternal[]): EditStatus;
protected tryApplyChangesInternal(...changes: readonly ChangeInternal[]): EditStatus;
protected tryApplyChangesInternal(...changes: RestOrArray<ChangeInternal>): EditStatus {
assert(this.currentEdit !== undefined, 'Changes must be applied as part of an ongoing edit.');
assert(this.currentEdit !== undefined, 0x603 /* Changes must be applied as part of an ongoing edit. */);
const changeArray = unwrapRestOrArray(changes);
const { status } = this.currentEdit.applyChanges(changeArray);
if (status === EditStatus.Applied) {
Expand Down Expand Up @@ -305,7 +306,7 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
public tryApplyEdit(...changes: RestOrArray<Change>): EditId | undefined {
this.openEdit();

assert(this.currentEdit !== undefined, 'Changes must be applied as part of an ongoing edit.');
assert(this.currentEdit !== undefined, 0x604 /* Changes must be applied as part of an ongoing edit. */);
const changeArray = unwrapRestOrArray(changes);
const { status } = this.currentEdit.applyChanges(changeArray.map((c) => this.tree.internalizeChange(c)));
if (status === EditStatus.Applied) {
Expand All @@ -329,15 +330,15 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
* @returns - the result of the rebase.
*/
public rebaseCurrentEdit(): EditValidationResult.Valid | EditValidationResult.Invalid {
assert(this.currentEdit !== undefined, 'An edit is not open.');
assert(this.currentEdit.status === EditStatus.Applied, 'Local edits should always be valid.');
assert(this.currentEdit !== undefined, 0x605 /* An edit is not open. */);
assert(this.currentEdit.status === EditStatus.Applied, 0x606 /* Local edits should always be valid. */);
// When closed, the result might indicate Malformed due to unused detached entities.
// This is not an error, as the edit was still open and can still use those entities.
const priorResults = this.currentEdit.close();
const rebasedEdit = TransactionInternal.factory(this.latestCommittedView).applyChanges(priorResults.changes);
assert(
rebasedEdit.status !== EditStatus.Malformed,
'Malformed changes should have been caught on original application.'
0x607 /* Malformed changes should have been caught on original application. */
);
let status: EditValidationResult.Valid | EditValidationResult.Invalid;
if (rebasedEdit.status === EditStatus.Invalid) {
Expand All @@ -357,7 +358,7 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
*/
public abortEdit(): void {
const { currentEdit } = this;
assert(currentEdit !== undefined, 'An edit is not open.');
assert(currentEdit !== undefined, 0x608 /* An edit is not open. */);
this.currentEdit = undefined;
this.emitChange();
}
Expand All @@ -369,7 +370,7 @@ export abstract class Checkout extends EventEmitterWithErrorHandling<ICheckoutEv
*/
public getEditStatus(): EditStatus {
const { currentEdit } = this;
assert(currentEdit !== undefined, 'An edit is not open.');
assert(currentEdit !== undefined, 0x609 /* An edit is not open. */);
// TODO: could this ever be anything other than 'Applied'
// TODO: shouldn't this be an EditValidationResult since 'Applied' does not indicate the edit has been applied?
return currentEdit.status;
Expand Down
12 changes: 6 additions & 6 deletions experimental/dds/tree/src/EditLog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents
const id = editIds[editIndex];
this.sequencedEdits.push({ id, ...edit });
const encounteredEditId = this.allEditIds.get(id);
assert(encounteredEditId === undefined, 'Duplicate acked edit.');
assert(encounteredEditId === undefined, 0x60a /* Duplicate acked edit. */);
this.allEditIds.set(id, { isLocal: false, index: editIndex });
}
} else {
Expand Down Expand Up @@ -387,7 +387,7 @@ export class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents

if (orderedEdit.isLocal) {
const firstLocal = this.allEditIds.get(this.localEdits[0].id) ?? fail('edit not found');
assert(firstLocal.isLocal, 'local edit should be local');
assert(firstLocal.isLocal, 0x60b /* local edit should be local */);
return (
this._earliestAvailableEditIndex +
this.numberOfSequencedEdits +
Expand Down Expand Up @@ -480,7 +480,7 @@ export class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents
): void {
assert(
minSequenceNumber >= this._minSequenceNumber,
'Sequenced edits should carry a monotonically increasing min number'
0x60c /* Sequenced edits should carry a monotonically increasing min number */
);
this._minSequenceNumber = minSequenceNumber;

Expand All @@ -492,10 +492,10 @@ export class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents
const encounteredEditId = this.allEditIds.get(id);
if (encounteredEditId !== undefined) {
// New edit already exits: it must have been a local edit.
assert(encounteredEditId.isLocal, 'Duplicate acked edit.');
assert(encounteredEditId.isLocal, 0x60d /* Duplicate acked edit. */);
// Remove it from localEdits. Due to ordering requirements, it must be first.
const oldLocalEditId = this.localEdits.shift()?.id ?? fail('Local edit should exist');
assert(oldLocalEditId === id, 'Causal ordering should be upheld');
assert(oldLocalEditId === id, 0x60e /* Causal ordering should be upheld */);
}

this.sequencedEdits.push(edit);
Expand Down Expand Up @@ -537,7 +537,7 @@ export class EditLog<TChange = unknown> extends TypedEventEmitter<IEditLogEvents
private evictEdits(): void {
assert(
this.sequenceNumberToIndex !== undefined,
'Edits should never be evicted if the target length is set to infinity'
0x60f /* Edits should never be evicted if the target length is set to infinity */
);

const minSequenceIndex =
Expand Down
Loading

0 comments on commit 1f13911

Please sign in to comment.