Skip to content

feat(patterns): helper for interface guard inheritance#2953

Merged
erights merged 2 commits intomasterfrom
markm-support-interface-inheritance
Sep 17, 2025
Merged

feat(patterns): helper for interface guard inheritance#2953
erights merged 2 commits intomasterfrom
markm-support-interface-inheritance

Conversation

@erights
Copy link
Contributor

@erights erights commented Sep 14, 2025

Closes: #XXXX
Refs: https://hackmd.io/@rekmarks/H1X6VtP5eg#

Description

https://hackmd.io/@rekmarks/H1X6VtP5eg# @rekmarks explains the need to express that one interface guard effectively extends another. In a slack thread, @michaelfig explains how all we need is a helper that can extract the method guards from an super/base interface guard which can then be used with ... when defining a sub/derived interface guard. Revising the name to fit this PR, @michaelfig 's pattern is

const I2 = M.interface('I2', {
  ...getNamedMethodGuards(I1),
  doMore: M.call().returns(M.any()),
});

By putting the ... first, the sub/derived interface guard can override "inherited" interface guards as well as adding new ones.

Note that this ignores symbol-named method guards. This feature is deprecated anyway, and will hopefully disappear soon. (TODO links to PRs that will make symbol-named methods and method guards disappear.)

Security Considerations

By making it easier to express interface guards, programmers are more likely to use non-vacuous interface guards, i.e., with method guards. Without explicit method guards or patterns, our experience is that ad-hoc input validation is hard. Interface guards with method guards with patterns expresses the type-like portion of interface validation in a declarative, readable, reviewable, and sound manner. The remaining input validation burden on the manually written "raw" exo methods then is more like it would be in a soundly-statically-typed ocap language. In our before/after experience, this is typically much smaller and more reliably reviewable.

Thus, this change is good for security.

Scaling Considerations

none

Documentation Considerations

@michaelfig 's inheritance pattern is nice and should be explained somewhere. Where?

Testing Considerations

Tested in @endo/exo by exo-wobbly-point.test.js since that's already about class inheritance, which naturally goes with interface inheritance.

Compatibility Considerations

It ignores symbol-named methods. This is unlikely to cause any problems now, and will help prevent new problems when we withdraw that "feature".

By internally using getInterfaceGuardPayload, we remain tolerant of the old deprecated klass-based interface-guard representation. Unfortunately, this compat is still needed by agoric-sdk.

Upgrade Considerations

none. Unless I'm missing something?

@erights erights self-assigned this Sep 14, 2025
@erights erights requested a review from michaelfig September 14, 2025 02:36
@erights erights requested review from Copilot and rekmarks September 14, 2025 02:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a helper function getNamedMethodGuards to support interface guard inheritance patterns. The function enables developers to extend one interface guard from another using JavaScript's spread operator.

  • Adds getNamedMethodGuards function that extracts string-named method guards from an interface guard
  • Updates comment formatting for consistency with JSDoc standards
  • Fixes default guard assignment logic in exo-tools.js

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/patterns/src/patterns/getGuardPayloads.js Adds the new getNamedMethodGuards helper function and improves comment formatting
packages/exo/src/exo-tools.js Fixes default guard assignment to use undefined instead of the uninitialized variable

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@erights erights requested a review from Copilot September 14, 2025 14:51
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@erights erights force-pushed the markm-support-interface-inheritance branch 2 times, most recently from a4dba17 to ee45ea2 Compare September 16, 2025 03:05
@erights erights requested a review from Copilot September 16, 2025 03:05
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@erights erights force-pushed the markm-support-interface-inheritance branch from 24cc9d2 to 01b3db6 Compare September 16, 2025 03:15
@erights erights marked this pull request as ready for review September 16, 2025 03:18
@erights
Copy link
Contributor Author

erights commented Sep 16, 2025

Ready for review

@erights erights requested a review from Copilot September 16, 2025 03:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@erights erights force-pushed the markm-support-interface-inheritance branch 2 times, most recently from 01b3db6 to 679e7a8 Compare September 16, 2025 06:55
@erights erights requested a review from gibson042 September 16, 2025 08:13
Copy link
Contributor

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

@erights erights force-pushed the markm-support-interface-inheritance branch from 679e7a8 to 8937953 Compare September 17, 2025 23:27
@erights erights force-pushed the markm-support-interface-inheritance branch from 8937953 to 02afa86 Compare September 17, 2025 23:36
@erights erights merged commit e71faf4 into master Sep 17, 2025
19 checks passed
@erights erights deleted the markm-support-interface-inheritance branch September 17, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants