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

explicit exports of Zoe service and contract facet types #11075

Merged
merged 15 commits into from
Mar 4, 2025

Conversation

turadg
Copy link
Member

@turadg turadg commented Mar 4, 2025

refs: #6343
refs: #10811

Description

While working to move Fast USDC (#10811) I kept running into problems with types resolving. I started working on the tech debt of #6343 and slipped down that rabbit hole.

This makes the ambient type declarations of ZoeService and ZCF modules into explicit exports and updates a ton of code to cope. Review by commit!

Some collateral improvements along the way:

  • governance type improvements
  • return types of Zoe helpers
  • Typesscript 5.8 release
  • cosmic-swingset conflicting dependencies

Security Considerations

none

Scaling Considerations

none

Documentation Considerations

I don't think we have docs on type imports

Testing Considerations

CI

Upgrade Considerations

This will break modules importing the types-ambient.js files that are gone. Those were deep imports so not part of the package semver.

@turadg turadg requested review from dckc and Chris-Hibbert March 4, 2025 03:01
@turadg turadg requested a review from a team as a code owner March 4, 2025 03:01
@dckc
Copy link
Member

dckc commented Mar 4, 2025

This will break modules importing the types-ambient.js files that are gone. Those were deep imports so not part of the package semver.

My impression is that anything that another package can import is part of the package API. Help me find the definition of semver you're working with?

@dckc
Copy link
Member

dckc commented Mar 4, 2025

This looks like progress on some other related issues:

Perhaps some of those should be closed as dups / not planned at some point.

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 skimmed each of the commits; the changes all look straightforward / rote with no runtime impact (except 1 possible case).

I'm not quite clear on the DX impact on getPublicFacet; I should look into that more.

"atLeast": 76.28
"atLeast": 76.25
Copy link
Member

Choose a reason for hiding this comment

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

What should I look for when reviewing changes in typeCoverage floor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally it goes up. It should never go down too much, per reviewer's judgement

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a dashboard?

// For ZCF which is only available ambiently
/// <reference types="@agoric/zoe/src/contractFacet/types-ambient" />
import type { ZCF } from '@agoric/zoe';
Copy link
Member

Choose a reason for hiding this comment

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

👏

Comment on lines +76 to 77
/** @type {any} */
const electorateInstance = await E(zoe).getInstance(invitation);
Copy link
Member

Choose a reason for hiding this comment

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

did getInstance get hit by the same thing that affected getPublicFacet?

* @param {V} value
* @returns {MathHelpers<V>}
*/
export const assertValueGetHelpers = value =>
// @ts-expect-error cast
helpers[assertValueGetAssetKind(value)];

/** @type {(allegedBrand: Brand, brand?: Brand) => void} */
/**
* @type {(allegedBrand: Brand<any>, brand?: Brand<any>) => void}
Copy link
Member

Choose a reason for hiding this comment

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

Brand's type parameter is no longer optional? If I'm reading that right, that's an awfully big DX regression.

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 still is but the default is AssetKind, not any. This change was needed only here. I didn't look deeply into why

@@ -31,9 +31,10 @@ export const BridgeId = /** @type {const} */ ({
});
harden(BridgeId);

/** @satisfies {Record<string, BridgeId>} */
export const CosmosInitKeyToBridgeId = {
Copy link
Member

Choose a reason for hiding this comment

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

harden this while we're here?

slippery slope, I suppose. This PR is already pretty big. And I think so far I haven't see any changes that have runtime impact.

Comment on lines 24 to 25
// XXX runtime import of types
import './internal-types.js';
Copy link
Member

Choose a reason for hiding this comment

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

how could this have runtime impact? it's a .ts file; don't we provide a companion .js file that's empty?

Copy link
Member Author

Choose a reason for hiding this comment

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

good point. I should say "side-effect" import is more accurate.

Comment on lines 118 to 126
bundleID: BundleID,
bundleID: string,
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 an unfortunate regression... or ... was BundleID previously any here?

Copy link
Member Author

@turadg turadg Mar 4, 2025

Choose a reason for hiding this comment

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

changed because the type couldn't resolve. But I think it wasn't serving much value. The property is named bundleId. The type was always string.

Is there anything more specific about a BundIeID than string? Maybe b1${string}

Copy link
Member

Choose a reason for hiding this comment

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

the type couldn't resolve.

That's the sort of thing I had in mind when asking whether it was previously any.

https://github.com/Agoric/agoric-sdk/blob/master/packages/SwingSet/src/types-external.js#L169 doesn't have any non-trivial JSDoc, but https://github.com/Agoric/agoric-sdk/blob/master/packages/SwingSet/docs/bundles.md#bundleids has a couple paragraphs of documentation.

I'm pretty sure there's a b0- thing too, though the swingset docs seem to exclude it.

I think some sort of // XXX reconnect to BundleID type docs marker is worthwhile. Not critical.

Copy link
Contributor

Choose a reason for hiding this comment

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

b1-${string}.

Copy link
Contributor

Choose a reason for hiding this comment

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

My comment was written before I saw Dan's. I was merely pointing out the dash in the pattern, not responding to the possibility of b0-. I think b0- is used in different places, but I'd check with @kriskowal to be sure.

@Agoric Agoric deleted a comment from dckc Mar 4, 2025
@Chris-Hibbert
Copy link
Contributor

Can we say this closes #8645?

Copy link

cloudflare-workers-and-pages bot commented Mar 4, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2198f64
Status: ✅  Deploy successful!
Preview URL: https://8b8891e0.agoric-sdk.pages.dev
Branch Preview URL: https://6343-unambient-zoe.agoric-sdk.pages.dev

View logs

@turadg
Copy link
Member Author

turadg commented Mar 4, 2025

Can we say this closes #8645?

I don't think this touches that

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.

#10811 is sufficiently important that this is worth landing even if it results in a few bumps in the road.

@turadg turadg force-pushed the 6343-unambient-zoe branch from 801823c to 6b67182 Compare March 4, 2025 19:30
@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label Mar 4, 2025
"atLeast": 76.28
"atLeast": 76.25
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a dashboard?

@@ -688,7 +689,7 @@ export {};
*
* @param {ERef<ZoeService>} zoe
* @param {import('@agoric/zoe/src/zoeService/utils.js').Instance<(zcf: ZCF<GovernanceTerms<{}>>) => {}>} allegedGoverned
* @param {Instance} allegedGovernor
* @param {Instance<(zcf) => {publicFacet: GovernorPublic}>} allegedGovernor
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 pretty sure the allegedGovernor (here and in AssertContractElectorate) is an instance. Doesn't this say it's a function? The first use in both funct is

  const allegedGovernorPF = E(zoe).getPublicFacet(allegedGovernor);

Copy link
Member Author

Choose a reason for hiding this comment

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

This also says it's an Instance. What I added is a contract start fn type parameter so downstream uses know what is the result of starting the instance

@@ -27,6 +27,7 @@ const assertContractGovernance = async (
await Promise.all([allegedGovernedTermsP, realGovernedP]);

assert(
// @ts-expect-error XXX types
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you have a theory?

Copy link
Member Author

Choose a reason for hiding this comment

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

just tech debt

@@ -232,6 +232,7 @@ type WellKnownContracts = {
provisionPool: typeof import('@agoric/inter-protocol/src/provisionPool.js').start;
priceAggregator: typeof import('@agoric/inter-protocol/src/price/fluxAggregatorContract.js').start;
reserve: typeof import('@agoric/inter-protocol/src/reserve/assetReserve.js').start;
reserveGovernor: typeof import('@agoric/governance/src/contractGovernor.js').start;
Copy link
Contributor

Choose a reason for hiding this comment

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

redundant with contractGovernor?

Copy link
Member Author

Choose a reason for hiding this comment

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

no because this is another entry in the space. it just happens to have the same type as contractGovernor

Comment on lines 118 to 126
bundleID: BundleID,
bundleID: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

b1-${string}.

@@ -112,7 +113,8 @@ export const start = async (zcf, privateArgs, baggage) => {
trace('makeStakeBldInvitation', give);
const { holder } = await makeLocalAccountKit();
/** @type {Record<string, Payment<'nat'>>} */
// @ts-expect-error XXX PaymentPKeywordRecord throught deeplyFulfilled will be a PaymnentKeywordRecord
// eslint-disable-next-line @typescript-eslint/ban-ts-comment -- fails only through some build paths
// @ts-ignore XXX PaymentPKeywordRecord throught deeplyFulfilled will be a PaymnentKeywordRecord
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's fix the typos. This is really hard to read as is.

Suggested change
// @ts-ignore XXX PaymentPKeywordRecord throught deeplyFulfilled will be a PaymnentKeywordRecord
// @ts-ignore XXX PaymentPKeywordRecord, though after deeplyFulfilled it will be a PaymentKeywordRecord

Copy link
Member Author

@turadg turadg Mar 4, 2025

Choose a reason for hiding this comment

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

if I have to do another push I'll include this

b1-${string}

Good suggestion. I did try that and a bunch of places have full wide string or use a different literal like id (in a test). So out of scope

Is there a dashboard?

nope

Copy link
Contributor

Choose a reason for hiding this comment

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

Where do these numbers come from? What do they get compared to?

Copy link
Member Author

Choose a reason for hiding this comment

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

try git grep typeCoverage

@turadg turadg force-pushed the 6343-unambient-zoe branch from 6b67182 to 2198f64 Compare March 4, 2025 20:04
Copy link
Contributor

mergify bot commented Mar 4, 2025

This pull request has been removed from the queue for the following reason: pull request manually updated.

The pull request #11075 has been manually updated

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@turadg
Copy link
Member Author

turadg commented Mar 4, 2025

@mergify requeue

Copy link
Contributor

mergify bot commented Mar 4, 2025

requeue

✅ The queue state of this pull request has been cleaned. It can be re-embarked automatically

@mergify mergify bot merged commit 3d98aac into master Mar 4, 2025
84 checks passed
@mergify mergify bot deleted the 6343-unambient-zoe branch March 4, 2025 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants