Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tree: make field assignment safer #23053

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

CraigMacomber
Copy link
Contributor

Description

Fixes two typing issues related to assignment of fields.

One issue is tracked by AB:9129

See changeset for details.

Breaking Changes

It's possible that an application relied on this unsafety to assign to fields with non-exact schema. This is unlikely since creating such nodes is not allowed by the types already.

Assignment of identifier fields unconditionally errors at runtime, so it is unlikely anyone depended on that compiling.

Reviewer Guidance

The review process is outlined on this wiki page.

@CraigMacomber CraigMacomber requested review from a team as code owners November 11, 2024 22:33
@github-actions github-actions bot added area: dds Issues related to distributed data structures area: dds: tree area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct changeset-present public api change Changes to a public API base: main PRs targeted against main branch labels Nov 11, 2024
@@ -234,10 +236,99 @@ describeHydration(
}) {}
const n = init(HasId, {});
assert.throws(() => {
// TODO: AB:9129: this should not compile
// @ts-expect-error this should not compile
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test which was tracking the known part of this issue. It now works as expected for non-recursive objects.

@@ -294,9 +294,9 @@ describe("SharedTreeCore", () => {
});

const sf = new SchemaFactory("0x4a6 repro");
const TestNode = sf.objectRecursive("test node", {
class TestNode extends sf.objectRecursive("test node", {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not required: I simply made it to get much better compile errors when debugging, and left it so other in the future can continue to have much cleaner errors if this code breaks again.

: never;

/**
* Suitable for assignment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything more we can say here?

Copy link
Collaborator

@msfluid-bot msfluid-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Coverage Summary

↓ packages.dds.tree.src.simple-tree.api:
Line Coverage Change: -0.05%    Branch Coverage Change: No change
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 88.76% 88.76% → No change
Line Coverage 82.28% 82.23% ↓ -0.05%
↑ packages.dds.tree.src.simple-tree:
Line Coverage Change: 0.03%    Branch Coverage Change: No change
Metric NameBaseline coveragePR coverageCoverage Diff
Branch Coverage 94.07% 94.07% → No change
Line Coverage 97.23% 97.26% ↑ 0.03%

Baseline commit: cc3fb6d
Baseline build: 306250
Happy Coding!!

Code coverage comparison check passed!!

@msfluid-bot
Copy link
Collaborator

msfluid-bot commented Nov 11, 2024

@fluid-example/bundle-size-tests: +245 Bytes
Metric NameBaseline SizeCompare SizeSize Diff
aqueduct.js 464.33 KB 464.36 KB +35 Bytes
azureClient.js 563.18 KB 563.23 KB +49 Bytes
connectionState.js 724 Bytes 724 Bytes No change
containerRuntime.js 262.48 KB 262.5 KB +14 Bytes
fluidFramework.js 426.84 KB 426.85 KB +14 Bytes
loader.js 134.18 KB 134.19 KB +14 Bytes
map.js 42.71 KB 42.71 KB +7 Bytes
matrix.js 148.36 KB 148.36 KB +7 Bytes
odspClient.js 528.97 KB 529.02 KB +49 Bytes
odspDriver.js 97.88 KB 97.9 KB +21 Bytes
odspPrefetchSnapshot.js 42.81 KB 42.83 KB +14 Bytes
sharedString.js 164.26 KB 164.27 KB +7 Bytes
sharedTree.js 417.3 KB 417.3 KB +7 Bytes
Total Size 3.37 MB 3.37 MB +245 Bytes

Baseline commit: cc3fb6d

Generated by 🚫 dangerJS against 90a79f5

@CraigMacomber
Copy link
Contributor Author

I missed a case in the implementation. It does not handler optional fields very well.

Also looking at possible usage, I think this change should be paired with a new API, maybe TreeAlpha.setField(node, property, content) which can be use in cases where this restriction is overly aggressive due to microsoft/TypeScript#43826

That would provide an option with typing that matches ArrayNode.insert() and TreeView.root.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 5 out of 17 changed files in this pull request and generated no suggestions.

Files not reviewed (12)
  • packages/dds/tree/api-report/tree.legacy.public.api.md: Evaluated as low risk
  • packages/dds/tree/api-report/tree.alpha.api.md: Evaluated as low risk
  • .changeset/metal-sloths-join.md: Evaluated as low risk
  • packages/dds/tree/src/index.ts: Evaluated as low risk
  • packages/dds/tree/src/simple-tree/index.ts: Evaluated as low risk
  • packages/dds/tree/src/test/shared-tree-core/sharedTreeCore.spec.ts: Evaluated as low risk
  • packages/framework/fluid-framework/api-report/fluid-framework.beta.api.md: Evaluated as low risk
  • packages/framework/fluid-framework/api-report/fluid-framework.public.api.md: Evaluated as low risk
  • packages/framework/fluid-framework/api-report/fluid-framework.legacy.public.api.md: Evaluated as low risk
  • packages/dds/tree/api-report/tree.legacy.alpha.api.md: Evaluated as low risk
  • packages/dds/tree/src/simple-tree/api/typesUnsafe.ts: Evaluated as low risk
  • packages/framework/fluid-framework/api-report/fluid-framework.legacy.alpha.api.md: Evaluated as low risk

Tip: Copilot only keeps its highest confidence comments to reduce noise and keep you focused. Learn more

Copy link
Contributor

🔗 No broken links found! ✅

Your attention to detail is admirable.

linkcheck output


> [email protected] ci:linkcheck /home/runner/work/FluidFramework/FluidFramework/docs
> start-server-and-test ci:start 1313 linkcheck:full

1: starting server using command "npm run ci:start"
and when url "[ 'http://127.0.0.1:1313' ]" is responding with HTTP status code 200
running tests using command "npm run linkcheck:full"


> [email protected] ci:start
> http-server ./public --port 1313 --silent


> [email protected] linkcheck:full
> npm run linkcheck:fast -- --external


> [email protected] linkcheck:fast
> linkcheck http://localhost:1313 --skip-file skipped-urls.txt --external

Crawling...

Stats:
  443722 links
    3414 destination URLs
       2 URLs ignored
       0 warnings
       0 errors


@CraigMacomber CraigMacomber marked this pull request as draft November 13, 2024 23:36
@CraigMacomber CraigMacomber mentioned this pull request Nov 13, 2024
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: tree area: dds Issues related to distributed data structures area: framework Framework is a tag for issues involving the developer framework. Eg Aqueduct base: main PRs targeted against main branch changeset-present public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants