Skip to content

Commit

Permalink
build(client): Tag asserts for RC5 release (microsoft#21457)
Browse files Browse the repository at this point in the history
Tags asserts for the RC5 release.

Command used:

```shell
pnpm policy-check:asserts
```

Also updated the biome config to properly exclude the generated file,
and updated scripts to call `format` instead of `pretty-quick`.
  • Loading branch information
tylerbutler authored Jun 19, 2024
1 parent d41c7ff commit c7ff2ae
Show file tree
Hide file tree
Showing 25 changed files with 145 additions and 140 deletions.
2 changes: 1 addition & 1 deletion biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
".git-blame-ignore-revs",

// Generated by policy-check
"packages/runtime/test-runtime-utils/src/assertionShortCodesMap.ts",
"**/assertionShortCodesMap.ts",

// This is a test file
"tools/markdown-magic/test/include.md",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"lint:fix": "fluid-build --task lint:fix",
"policy-check": "flub check policy",
"policy-check-help": "echo Detect (and error on) policy-check violations, like package.json sorting, copyright headers etc. Excludes assert-short-code. Run the check or \"pnpm flub check policy --listHandlers\" for a full list.",
"policy-check:asserts": "flub generate assertTags --all && pretty-quick",
"policy-check:asserts": "flub generate assertTags --all && npm run format",
"policy-check:fix": "flub check policy --excludeHandler assert-short-codes --fix",
"policy-check:fix-help": "echo Fix policy-check violations excludes assert-short-code/",
"prettier": "fluid-build --task prettier",
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/shared-object-base/src/sharedObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ export abstract class SharedObject<
// TelemetryContext needs to implment a get function
assert(
"get" in telemetryContext && typeof telemetryContext.get === "function",
"received context must have a get function",
0x97e /* received context must have a get function */,
);

const prevTotal = ((telemetryContext as TelemetryContext).get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function readValue(
const streamValue = readStream(stream);
assert(
typeof streamValue === "number" || typeof streamValue === "string",
"identifier must be string or number.",
0x997 /* identifier must be string or number. */,
);
const idCompressor = idDecodingContext.idCompressor;
return typeof streamValue === "number"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ export function encodeValue(
assert(shape.length === 1, 0x740 /* expected a single constant for value */);
} else if (shape === SpecialField.Identifier) {
// This case is a special case handling the encoding of identifier fields.
assert(value !== undefined, "required value must not be missing");
assert(value !== undefined, 0x998 /* required value must not be missing */);
outputBuffer.push(value);
} else {
// EncodedCounter case:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class NodeShape extends Shape<EncodedChunkShape> implements NodeEncoder {

private getValueToEncode(cursor: ITreeCursorSynchronous, cache: EncoderCache): Value {
if (this.value === 0) {
assert(typeof cursor.value === "string", "identifier must be type string");
assert(typeof cursor.value === "string", 0x9aa /* identifier must be type string */);
if (isStableId(cursor.value)) {
const sessionSpaceCompressedId = cache.idCompressor.tryRecompress(cursor.value);
if (sessionSpaceCompressedId !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ export function fieldShaper(
const nodeEncoder = type !== undefined ? treeHandler.shapeFromTree(type) : anyNodeEncoder;
if (kind.multiplicity === Multiplicity.Single) {
if (field.kind === identifierFieldKindIdentifier) {
assert(type !== undefined, "field type must be defined in identifier field");
assert(type !== undefined, 0x999 /* field type must be defined in identifier field */);
const nodeSchema = storedSchema.nodeSchema.get(type);
assert(nodeSchema !== undefined, "nodeSchema must be defined");
assert(nodeSchema !== undefined, 0x99a /* nodeSchema must be defined */);
assert(
nodeSchema instanceof LeafNodeStoredSchema,
"nodeSchema must be LeafNodeStoredSchema",
0x99b /* nodeSchema must be LeafNodeStoredSchema */,
);
assert(
nodeSchema.leafValue === ValueSchema.String,
"identifier field can only be type string",
0x99c /* identifier field can only be type string */,
);
const identifierNodeEncoder = new NodeShape(
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class EagerMapTreeNode<TSchema extends FlexTreeNodeSchema> implements Map
public readonly mapTree: MapTree,
private location: LocationInField | undefined,
) {
assert(!nodeCache.has(mapTree), "A node already exists for the given MapTree");
assert(!nodeCache.has(mapTree), 0x98b /* A node already exists for the given MapTree */);
nodeCache.set(mapTree, this);

// Fully demand the tree to ensure that parent pointers are present and accurate on all nodes.
Expand All @@ -164,7 +164,10 @@ export class EagerMapTreeNode<TSchema extends FlexTreeNodeSchema> implements Map
* @remarks A node may only be adopted to a new parent one time, and only if it was not constructed with a parent.
*/
public adopt(parent: MapTreeField<FlexAllowedTypes>, index: number): void {
assert(this.location === undefined, "Node may not be adopted if it already has a parent");
assert(
this.location === undefined,
0x98c /* Node may not be adopted if it already has a parent */,
);
this.location = { parent, index };
}

Expand Down Expand Up @@ -252,9 +255,12 @@ export class EagerMapTreeNode<TSchema extends FlexTreeNodeSchema> implements Map
{ parent: field, index },
);
// These next asserts detect the case where `getOrCreateChild` gets a cache hit of a different node than the one we're trying to create
assert(child.location !== undefined, "Expected node to have parent");
assert(child.location.parent.parent === this, "Node may not be multi-parented");
assert(child.location.index === index, "Node may not be multi-parented");
assert(child.location !== undefined, 0x98d /* Expected node to have parent */);
assert(
child.location.parent.parent === this,
0x98e /* Node may not be multi-parented */,
);
assert(child.location.index === index, 0x98f /* Node may not be multi-parented */);
child.walkTree();
}
}
Expand Down Expand Up @@ -440,7 +446,10 @@ class MapTreeField<T extends FlexAllowedTypes> implements FlexTreeField {
public readonly parent: FlexTreeNode | undefined,
public readonly mapTrees: readonly MapTree[],
) {
assert(!fieldCache.has(mapTrees), "A field already exists for the given MapTrees");
assert(
!fieldCache.has(mapTrees),
0x990 /* A field already exists for the given MapTrees */,
);
fieldCache.set(mapTrees, this);

// When this field is created (which only happens one time, because it is cached), all the children become parented for the first time.
Expand All @@ -450,7 +459,7 @@ class MapTreeField<T extends FlexAllowedTypes> implements FlexTreeField {
if (mapTreeNodeChild !== undefined) {
assert(
mapTreeNodeChild.parentField.parent === rootMapTreeField,
"Node is already parented under a different field",
0x991 /* Node is already parented under a different field */,
);
mapTreeNodeChild.adopt(this, i);
}
Expand All @@ -469,7 +478,7 @@ class MapTreeField<T extends FlexAllowedTypes> implements FlexTreeField {

public isSameAs(other: FlexTreeField): boolean {
if (other.parent === this.parent && other.key === this.key) {
assert(other === this, "Expected field to be cached");
assert(other === this, 0x992 /* Expected field to be cached */);
return true;
}

Expand Down Expand Up @@ -690,7 +699,7 @@ function getOrCreateChild(
allowedTypes
.map((t) => (isLazy(t) ? t() : t))
.find((t): t is FlexTreeNodeSchema => {
assert(t !== "Any", "'Any' type is not supported");
assert(t !== "Any", 0x993 /* 'Any' type is not supported */);
return t.name === mapTree.type;
}) ?? fail("Unsupported node schema");

Expand Down Expand Up @@ -735,7 +744,7 @@ function createNode<TSchema extends FlexTreeNodeSchema>(
if (schemaIsObjectNode(nodeSchema)) {
return new EagerMapTreeNode(nodeSchema, mapTree, parentField);
}
assert(false, "Unrecognized node kind");
assert(false, 0x994 /* Unrecognized node kind */);
}

/** Creates a field with the given attributes, or returns a cached field if there is one */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ export class ObjectForest implements IEditableForest {
*/
const preEdit = (): void => {
this.events.emit("beforeChange");
assert(this.currentCursors.has(cursor), "missing visitor cursor while editing");
assert(
this.currentCursors.has(cursor),
0x995 /* missing visitor cursor while editing */,
);
if (this.currentCursors.size > 1) {
const unexpectedSources = [...this.currentCursors].flatMap((c) =>
c === cursor ? [] : c.source ?? null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function makeV2Codec(
context: ChangeEncodingContext,
): RevisionTag {
if (encodedRevision === undefined) {
assert(context.revision !== undefined, "Implicit revision should be provided");
assert(context.revision !== undefined, 0x996 /* Implicit revision should be provided */);
return context.revision;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class BranchCommitEnricher<TChange> {
if (concludesOuterTransaction) {
assert(
this.transactionEnricher !== undefined,
"Unexpected transaction commit without transaction steps",
0x97f /* Unexpected transaction commit without transaction steps */,
);
enrichedChange = this.transactionEnricher.getComposedChange(commit.revision);
} else {
Expand All @@ -92,7 +92,7 @@ export class BranchCommitEnricher<TChange> {
*/
public getPreparedCommit(commit: GraphCommit<TChange>): GraphCommit<TChange> {
const prepared = this.preparedCommits.get(commit);
assert(prepared !== undefined, "Unknown commit");
assert(prepared !== undefined, 0x980 /* Unknown commit */);
this.preparedCommits.delete(commit);
return prepared;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export class DefaultResubmitMachine<TChange> implements ResubmitMachine<TChange>
public onCommitSubmitted(commit: GraphCommit<TChange>): void {
if (this.isInResubmitPhase) {
const toResubmit = this.resubmitQueue.shift();
assert(toResubmit === commit, "Unexpected commit submitted during resubmit phase");
assert(
toResubmit === commit,
0x981 /* Unexpected commit submitted during resubmit phase */,
);
}
this.inFlightQueue.push(commit);
}
Expand Down Expand Up @@ -109,7 +112,7 @@ export class DefaultResubmitMachine<TChange> implements ResubmitMachine<TChange>
public peekNextCommit(): GraphCommit<TChange> {
assert(
this.isInResubmitPhase,
"No available commit to resubmit outside of resubmit phase",
0x982 /* No available commit to resubmit outside of resubmit phase */,
);
return this.resubmitQueue[0];
}
Expand Down
4 changes: 2 additions & 2 deletions packages/dds/tree/src/shared-tree-core/sharedTreeCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange> extends
) {
assert(
change.newCommits.length === 1,
"Unexpected number of commits when committing transaction",
0x983 /* Unexpected number of commits when committing transaction */,
);
this.commitEnricher.prepareCommit(change.newCommits[0], true);
}
Expand Down Expand Up @@ -412,7 +412,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange> extends
);
assert(
this.resubmitMachine.isInResubmitPhase !== false,
"Invalid resubmit outside of resubmit phase",
0x984 /* Invalid resubmit outside of resubmit phase */,
);
const enrichedCommit = this.resubmitMachine.peekNextCommit();
this.submitCommit(enrichedCommit, localOpMetadata, true);
Expand Down
11 changes: 7 additions & 4 deletions packages/dds/tree/src/shared-tree-core/transactionEnricher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,26 @@ export class TransactionEnricher<TChange> {

public commitCurrentTransaction(): void {
const commitsCommitted = this.transactionScopesStart.pop();
assert(commitsCommitted !== undefined, "No transaction to commit");
assert(commitsCommitted !== undefined, 0x985 /* No transaction to commit */);
}

public abortCurrentTransaction(): void {
const scopeStart = this.transactionScopesStart.pop();
assert(scopeStart !== undefined, "No transaction to abort");
assert(scopeStart !== undefined, 0x986 /* No transaction to abort */);
this.transactionCommits.length = scopeStart;
}

public addTransactionStep(commit: GraphCommit<TChange>): void {
assert(this.transactionScopesStart.length !== 0, "No transaction to add a step to");
assert(
this.transactionScopesStart.length !== 0,
0x987 /* No transaction to add a step to */,
);
const change = this.enricher.updateChangeEnrichments(commit.change, commit.revision);
this.transactionCommits.push({ ...commit, change });
}

public getComposedChange(revision: RevisionTag): TChange {
assert(this.transactionScopesStart.length === 0, "Transaction not committed");
assert(this.transactionScopesStart.length === 0, 0x988 /* Transaction not committed */);
const squashed = this.rebaser.compose(this.transactionCommits);
const tagged = this.rebaser.changeRevision(squashed, revision);
this.transactionCommits.length = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/shared-tree/treeCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
revertAge++;

const parentCommit = currentCommit.parent;
assert(parentCommit !== undefined, "expected to find a parent commit");
assert(parentCommit !== undefined, 0x9a9 /* expected to find a parent commit */);
currentCommit = parentCommit;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/simple-tree/arrayNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,6 @@ function validateIndexRange(
function prepareFieldCursorForInsert(cursor: ITreeCursorSynchronous): ITreeCursorSynchronous {
// TODO: optionally validate content against schema.

assert(cursor.mode === CursorLocationType.Fields, "should be in fields mode");
assert(cursor.mode === CursorLocationType.Fields, 0x9a8 /* should be in fields mode */);
return cursor;
}
2 changes: 1 addition & 1 deletion packages/dds/tree/src/simple-tree/toMapTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ function addDefaultsToMapTree(
}
break;
default:
assert(schema.kind === NodeKind.Leaf, "Unrecognized schema kind");
assert(schema.kind === NodeKind.Leaf, 0x989 /* Unrecognized schema kind */);
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/simple-tree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export abstract class TreeNode implements WithType {
return false;
}

assert("prototype" in schema, "expected class based schema");
assert("prototype" in schema, 0x98a /* expected class based schema */);
return inPrototypeChain(schema.prototype, this.prototype);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ class ConnectionStateHandler implements IConnectionStateHandler {

assert(
!this.waitingForLeaveOp,
"leave timer can't be set as we have not had access to quorum",
0x99d /* leave timer can't be set as we have not had access to quorum */,
);

// This check is required for scenario of loading container from pending state, and ensuring there is no way
Expand Down
4 changes: 2 additions & 2 deletions packages/loader/container-loader/src/memoryBlobStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ export function tryInitializeMemoryDetachedBlobStorage(
);
}

assert(detachedStorage.size === 0, "Blob storage already initialized");
assert(detachedStorage.size === 0, 0x99e /* Blob storage already initialized */);
const maybeAttachmentBlobs = JSON.parse(attachmentBlobs);
assert(Array.isArray(maybeAttachmentBlobs), "Invalid attachmentBlobs");
assert(Array.isArray(maybeAttachmentBlobs), 0x99f /* Invalid attachmentBlobs */);

detachedStorage.initialize(maybeAttachmentBlobs);
}
Expand Down
10 changes: 5 additions & 5 deletions packages/loader/container-loader/src/protocol/quorum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export class QuorumClients
* Adds a new client to the quorum
*/
public addMember(clientId: string, details: ISequencedClient) {
assert(!!clientId, "clientId has to be non-empty string");
assert(!this.members.has(clientId), "clientId not found");
assert(!!clientId, 0x9a0 /* clientId has to be non-empty string */);
assert(!this.members.has(clientId), 0x9a1 /* clientId not found */);
this.members.set(clientId, details);
this.emit("addMember", clientId, details);

Expand All @@ -108,8 +108,8 @@ export class QuorumClients
* Removes a client from the quorum
*/
public removeMember(clientId: string) {
assert(!!clientId, "clientId has to be non-empty string");
assert(this.members.has(clientId), "clientId not found");
assert(!!clientId, 0x9a2 /* clientId has to be non-empty string */);
assert(this.members.has(clientId), 0x9a3 /* clientId not found */);
this.members.delete(clientId);
this.emit("removeMember", clientId);

Expand Down Expand Up @@ -311,7 +311,7 @@ export class QuorumProposals
local: boolean,
clientSequenceNumber: number,
) {
assert(!this.proposals.has(sequenceNumber), "sequenceNumber not found");
assert(!this.proposals.has(sequenceNumber), 0x9a4 /* sequenceNumber not found */);

const proposal = new PendingProposal(sequenceNumber, key, value, local);
this.proposals.set(sequenceNumber, proposal);
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/container-runtime/src/containerRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3972,7 +3972,7 @@ export class ContainerRuntime
const type = containerRuntimeMessage.type;
assert(
type !== ContainerMessageType.IdAllocation,
"IdAllocation should be submitted directly to outbox.",
0x9a5 /* IdAllocation should be submitted directly to outbox. */,
);
const message: BatchMessage = {
contents: serializedContent,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/container-runtime/src/dataStoreContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ export class LocalFluidDataStoreContextBase extends FluidDataStoreContext {
public getAttachGCData(telemetryContext?: ITelemetryContext): IGarbageCollectionData {
assert(
this.channel !== undefined,
"There should be a channel when generating attach GC data",
0x9a6 /* There should be a channel when generating attach GC data */,
);
return this.channel.getAttachGCData(telemetryContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export class Outbox {
*/
private rebase(rawBatch: IBatch, batchManager: BatchManager) {
assert(!this.rebasing, 0x6fb /* Reentrancy */);
assert(batchManager.options.canRebase, "BatchManager does not support rebase");
assert(batchManager.options.canRebase, 0x9a7 /* BatchManager does not support rebase */);

this.rebasing = true;
for (const message of rawBatch.content) {
Expand Down
Loading

0 comments on commit c7ff2ae

Please sign in to comment.