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

contract start types #7436

Merged
merged 7 commits into from
Apr 19, 2023
Merged

contract start types #7436

merged 7 commits into from
Apr 19, 2023

Conversation

turadg
Copy link
Member

@turadg turadg commented Apr 17, 2023

Description

No ticket. Nerd-sniped in #7426 (comment)

Tighter definition for startInstance, resulting in more installation types required in bootstrap.

That then brought up some governance types inconsistencies. Those have an issue so I punted with a comment.

There were two runtime changes to vaultFactory types which I separated.

Review by commit recommended.

Security Considerations

n/a

Scaling Considerations

n/a

Documentation Considerations

--

Testing Considerations

CI

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

I was reviewing by commit and then a force-push made me wonder if I should wait.

zcf?: ZCF,
privateArgs?: {},
baggage?: Baggage,
) => ERef<{ creatorFacet?: {}; publicFacet?: {} }>;
Copy link
Member

Choose a reason for hiding this comment

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

does {} mean any in this context?

Copy link
Member Author

Choose a reason for hiding this comment

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

here it's specifically an empty object, vs the any several lines down

: SF extends (zcf: { getTerms: () => {} }) => unknown
? { terms: any }
: {};
: never;

type StartResult<S> = S extends (...args: any) => Promise<infer U>
Copy link
Member

Choose a reason for hiding this comment

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

infer U is magic I have yet to learn. That makes this an "I don't see any critical problems" review and not a "I'm prepared to maintain this code" review.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a sort of syntactic sugar for extracting what matches in the condition https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#inferring-within-conditional-types

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

I need to understand the change in vats/src/core/types.js better.

Comment on lines +176 to +184
* centralSupply: Promise<Installation<import('@agoric/vats/src/centralSupply.js').start>>,
* committee: Promise<Installation<import('@agoric/governance/src/committee.js').start>>,
* contractGovernor: Promise<Installation<import('@agoric/governance/src/contractGovernor.js').start>>,
* econCommitteeCharter: Promise<Installation<import('@agoric/inter-protocol/src/econCommitteeCharter.js').start>>,
* feeDistributor: Promise<Installation<import('@agoric/inter-protocol/src/feeDistributor.js').start>>,
* mintHolder: Promise<Installation<import('@agoric/vats/src/mintHolder.js').prepare>>,
* psm: Promise<Installation<import('@agoric/inter-protocol/src/psm/psm.js').start>>,
* reserve: Promise<Installation<import('@agoric/inter-protocol/src/reserve/assetReserve.js').start>>,
* VaultFactory: Promise<Installation<import('@agoric/inter-protocol/src/vaultFactory/vaultFactory.js').start>>,
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a significant regression. I need to understand the motivation better.

There was some attempt to layer EconomyBootstrapSpace on top rather than putting that stuff here.

* }>} EconomyBootstrapSpace
*/

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll put these wherever they go. I just command-clicked installation in the param destructuring to find out where the defs were coming from. I'll try EconomyBootstrapSpace

Copy link
Member Author

Choose a reason for hiding this comment

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

Now I remember why I put them here: the keys are from WellKnownName which is the key of the installation property Record.

Changing that is out of scope, imo. Acceptable?

Copy link
Member

Choose a reason for hiding this comment

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

yes.

Copy link
Member

Choose a reason for hiding this comment

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

oic how this works now: econCommitteeCharter is not just any old installation... got it.

Comment on lines -268 to +266
return harden({});
return harden([]);
Copy link
Member

Choose a reason for hiding this comment

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

!

Copy link
Member Author

Choose a reason for hiding this comment

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

amended 9c4e487 after review to prevent drifts in the future

Copy link
Contributor

@Chris-Hibbert Chris-Hibbert left a comment

Choose a reason for hiding this comment

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

I don't see any problems with this, but, echoing @dckc, I can't approve this without understanding the answers to his questions.

@@ -302,3 +292,43 @@ test('initialPrice', /** @param {ExecutionContext} t */ async t => {
const q400 = await E(pa).quoteGiven(make(collateral.brand, 400n), debt.brand);
t.deepEqual(q400.quoteAmount.value[0].amountOut, make(debt.brand, 14200n));
});

test.skip('types', async t => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's intended that this be checked in with test.skip, it should have a comment saying why.

Copy link
Member

Choose a reason for hiding this comment

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

the comment on 303-305 works for me.

I guess moving it up could have made it easier to see.

Copy link
Member Author

Choose a reason for hiding this comment

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

I put in into a separate (non-Ava) test file to avoid the confusion. Doing that also let me use .ts syntax for better test coverage.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still confused. I infer from the latest comment that the .ts file was intended to replace this test, but the test is still here.

I don't understand how a skipped test helps to declare types, or what other function it might serve.

Does the .ts file add code to our system, or does it only impact type declarations?

@turadg turadg requested review from dckc and Chris-Hibbert April 18, 2023 22:22
Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

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

looks good

@turadg turadg added the automerge:no-update (expert!) Automatically merge without updates label Apr 18, 2023
@@ -302,3 +292,43 @@ test('initialPrice', /** @param {ExecutionContext} t */ async t => {
const q400 = await E(pa).quoteGiven(make(collateral.brand, 400n), debt.brand);
t.deepEqual(q400.quoteAmount.value[0].amountOut, make(debt.brand, 14200n));
});

test.skip('types', async t => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm still confused. I infer from the latest comment that the .ts file was intended to replace this test, but the test is still here.

I don't understand how a skipped test helps to declare types, or what other function it might serve.

Does the .ts file add code to our system, or does it only impact type declarations?

Comment on lines +2 to +4
* @file uses .ts syntax to be able to declare types (e.g. of kit.creatorFacet as {})
* because "there is no JavaScript syntax for passing a a type argument"
* https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused about the contribution of this file. I thought .ts fles were for type declarations, but this looks like imperative code, though not working code. What is its impact? What types are being declared or implied? Does it run as code during tests, or is it parsed and discarded, or something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still confused. I infer from the latest comment that the .ts file was intended to replace this test, but the test is still here.

Sorry about that. I must have messed up a rebase. I've amended and push ed with the test.skip('types') removed.

I don't understand how a skipped test helps to declare types, or what other function it might serve.

The intent was to have some types tests co-located with the runtime tests for a particular specimen (e.g. scaledPriceAuthority). But it's better to keep purely types tests out of Ava tests so it doesn't report about skipping. Indeed, the thing being tested (type check) isn't being skipped at all.

Does the .ts file add code to our system, or does it only impact type declarations?

It's only read by the tsc checker run by yarn lint:types.

I thought .ts fles were for type declarations, but this looks like imperative code, though not working code.

.d.ts is for type declarations. .ts is transpiled to .js so it's for any code.. The test-d.ts is meant to convey that while it's a .ts it's for testing type defs. That's a convention of the tsd package.

What is its impact?

It just gets included in the tsc type check. So if something here starts erroring (or stops, because the ts-expect-error is not finding one) then it'll cause lint:types (and thus CI) to fail.

Does it run as code during tests, or is it parsed and discarded, or something else?

Ava won't run it because it doesn't match the pattern Ava looks for. It's parsed only by tsc. When the package gets built the tsc config will transpile it, but to a similarly ignored test file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanations. Would it make sense to add any of this as a comment to the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

It would have to be duplicated for each file. I've put it in the wiki: https://github.com/Agoric/agoric-sdk/wiki/Static-types-testing

Comment on lines +1695 to +1701
"@jest/schemas@^29.4.3":
version "29.4.3"
resolved "https://registry.yarnpkg.com/@jest/schemas/-/schemas-29.4.3.tgz#39cf1b8469afc40b6f5a2baaa146e332c4151788"
integrity sha512-VLYKXQmtmuEz6IxJsrZwzG9NvtkQsWNnWMsKxqWNu3+CnfzJQhp0WDDKWLVV9hLKr0l3SLLFRqcYHjhtyuDVxg==
dependencies:
"@sinclair/typebox" "^0.25.16"

Copy link
Contributor

Choose a reason for hiding this comment

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

it's unusual for check-ins to contain yarn.lock. Is it intentional here? What would it take to review it for correctness?

Copy link
Member Author

Choose a reason for hiding this comment

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

The commit added a devDpendency upon tsd. Almost any change in dependencies will change yarn.lock. Because that's automated there's not much to review. The important thing to review is the package.json changes. For yarn.lock you might want to verify there are no duplicates or that it hasn't grown dramatically. If there are duplicates they can be fixed with npx yarn-deduplicate.

@mergify mergify bot merged commit f3bb795 into master Apr 19, 2023
@mergify mergify bot deleted the ta/start-types branch April 19, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:no-update (expert!) Automatically merge without updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants