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

Fdc3 for web impl get agent refactor #1466

Open
wants to merge 73 commits into
base: fdc3-for-web-impl
Choose a base branch
from

Conversation

kriswest
Copy link
Contributor

@kriswest kriswest commented Dec 10, 2024

Describe your change

Significant refactor of the fdc3-get-agent package to align it with the Standard and a number of change fdc3-agent-proxy or fdc3-web-impl that were necessitated by the changes.

Changes:

  • Refactored Session Storage to use new format as introduced in Updating SessionStorage data format to additionally scope data #1442
  • Session Storage data is used to limit discovery options to those used previously in the session
  • The TimeoutLoader was eliminated in favour of timeouts in the individual loading strategies (as some actions in Desktop Agent Proxy interfaces can occur beyond the timeout, e.g. identity validation and UI setup)
  • AbstractWebMessaging was eliminated and separation of concerns achieved between fdc3-agent-proxy and fdc3-get-agent. The former only handles the DACP protocol (making it easier to use for other puprposes) while the latter handles all WCP messaging (including WCP6Goodbye) to set-up the message port connection in a browser.
  • GetInfo API calls are now handled by the fdc3-agent-proxy with a message exchange, rather than using cached data from identity validation step of the WCP.
  • Message exchanges use a constant 10 second timeout, rather than inheriting the discovery timeout - this timeout may need further examination - it should possibly be specified by the Desktop Agent, or just set to a long-ish value (e.g. 30 seconds). However, its worth noting that no FDC3 API calls should require a long value as any long-running tasks are handled via events (e.g. context and intent listening).
  • Renamed BasicDesktopAgent to DesktopAgentProxy to better represent its role.
  • Comms iframes must now respond to a hello message from the app, rather than simply firing off a handshake when they load - this ensures that they can handle the UI arguments provided in the hello message (and perhaps one day the FDC3 version requested)
  • Private Channel events use the updated schemas from Correcting privateChannelAddEventListenerRequest to include null as a valid listenerType #1446 for consistency (avoids unnecessary translation)
  • Corrected pagehide handling to only disconnect if persisted == false
  • Added some log messaging for getAgent and set many logs to debug level
  • Added Logging utility to prefix log messages and colourise (where supported). This could later be used to disable debug logging with an argument.
  • Typing
    • Reduces the number of any types and type overrides in many places - there are others still to address
    • Type imports from BrowserTypes are made specific (rather than importing the whole thing and taking parts of it - as this may produce a smaller module and is easier to maintain) - there are others still to address.
  • Linting
    • Pre-PR reports:
      • fdc3-agent-proxy ✖ 41 problems (41 errors, 0 warnings)
      • fdc3-web-impl ✖ 63 problems (63 errors, 0 warnings)
      • fdc3-get-agent ✖ 25 problems (25 errors, 0 warnings)
      • fdc3-for-web-reference-ui ✖ 7 problems (7 errors, 0 warnings)
      • demo 42 problems (42 errors, 0 warnings)
    • Post-PR reports:
      • fdc3-agent-proxy ✖ 3 problems (3 errors, 0 warnings)
      • fdc3-web-impl ✖ 23 problems (23 errors, 0 warnings)
      • fdc3-get-agent ✔️ 0 problems (0 errors, 0 warnings)
      • fdc3-for-web-reference-ui ✖ 4 problems (4 errors, 0 warnings)
      • demo ✖ 12 problems (12 errors, 0 warnings)
    • A step in the right direction, but more to do! Some are automatically fixable (double non-null assertions with !!) but I have left these in place as each should be reviewed to see if the assertion can be avoided through better typing or defensive programming.
  • Tests
    • Refactored fdc3-get-agent test infrastructure to better represent multiple windows, documents and iframes - previously only single window.document would represent the parent, child and iframes at times and was relying on the getAgent implementation considering its own window to be a possible parent and to set up messaging with it 0t this is now prevented
    • Introduced new tests for fdc3-getAgent covering SessionStorage use in detail, as well as a number of cases.
    • Added a variable to enable/disable debug logging for test infrastructure and created many log messages.

Related Issue

Addresses a number of issues in addition to working to improve the implementation generally:

resolves #1429
resolves #1430
resolves #1433
resolves #1445
resolves #1468

Contributor License Agreement

  • I acknowledge that a contributor license agreement is required and that I have one in place or will seek to put one in place ASAP.

Review Checklist

  • Issue: If a change was made to the FDC3 Standard, was an issue linked above?
  • N/A (working on unreleased implementation) CHANGELOG: Is a CHANGELOG.md entry included?
  • API changes: Does this PR include changes to any of the FDC3 APIs (DesktopAgent, Channel, PrivateChannel, Listener, Bridging)?
    • Docs & Sources: If yes, were both documentation (/docs) and sources updated?

      JSDoc comments on interfaces and types should be matched to the main documentation in /docs
    • Conformance tests: If yes, are conformance test definitions (/toolbox/fdc3-conformance) still correct and complete?

      Conformance test definitions should cover all required aspects of an FDC3 Desktop Agent implementation, which are usually marked with a MUST keyword, and optional features (SHOULD or MAY) where the format of those features is defined
    • Schemas: If yes, were changes applied to the Bridging and FDC3 for Web protocol schemas?

      The Web Connection protocol and Desktop Agent Communication Protocol schemas must be able to support all necessary aspects of the Desktop Agent API, while Bridging must support those aspects necessary for Desktop Agents to communicate with each other
      • If yes, was code generation (npm run build) run and the results checked in?

        Generated code will be found at /src/api/BrowserTypes.ts and/or /src/bridging/BridgingTypes.ts
  • Context types: Were new Context type schemas created or modified in this PR?
    • Were the field type conventions adhered to?
    • Was the BaseContext schema applied via allOf (as it is in existing types)?
    • Was a title and description provided for all properties defined in the schema?
    • Was at least one example provided?
    • Was code generation (npm run build) run and the results checked in?

      Generated code will be found at /src/context/ContextTypes.ts
  • Intents: Were new Intents created in this PR?

kriswest and others added 30 commits November 19, 2024 21:18
Individual timeouts allow for steps that our outside the timeout (identity validation)
ImplementationMetadata is now passed into AbstractMessaging's constructor and getting close to eliminating AbstractWebMessaging. Correcting typing and generics on a number of functions (replacing any and unqualified generics)
- Eliminate AbstractWebMessaging
- Messaging is no longer a Connectable (as the connection is provided to it - was previously a no-op)
- Handling getInfo via a message exchange rather than passing down through connection flow
- Messaging implementations no longer handle implementationMetadata, instead holding the AppIdentifier directly
- Renamed HandshakeSupport HeartbeatSupport as its no longer involved in holding implementaiton metadata.
- Improving typing and error handling (defensive coding) in get-agent-proxy
@kriswest
Copy link
Contributor Author

@robmoffat @julianna-ciq I think I've got all comments and issues resolved or at least responded, so I only have looking at timeouts (on open/raiseIntent etc.) left to do - and that could be a different PR...

Could you check any unresolved comments and see if you're happy or whether you think I need to take it further please.

robmoffat and others added 3 commits December 18, 2024 13:42
… logging tests so it's clearer what they're doing
…or-rm-patch1

Refactored FailoverHandler into separate smaller functions, tidied up…
Copy link

464 passed

Copy link

464 passed

Copy link
Contributor

@julianna-ciq julianna-ciq left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Member

@robmoffat robmoffat left a comment

Choose a reason for hiding this comment

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

nearly there!

packages/fdc3-agent-proxy/src/util.ts Show resolved Hide resolved

if (response.payload?.channel?.id) {
//handle successful responses - errors will already have been thrown by exchange above
if (response.payload.channel) {
Copy link
Member

Choose a reason for hiding this comment

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

can't we use your new throwIfUndefined here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have put it in and removed the log message, but the else has to stay so that we return on all branches.

};
handler(event);
} else {
console.error('PrivateChannelDisconnectEventListener was called for a different message type!', msg);
Copy link
Member

Choose a reason for hiding this comment

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

this line untested - and the message is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed the message - have not added a test, its just single log line. I do want it to create noise if this starts happening (rather than it happening silently) but ideally it never happens.

};
handler(event);
} else {
console.error('PrivateChannelDisconnectEventListener was called for a different message type!', msg);
Copy link
Member

Choose a reason for hiding this comment

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

this line untested and the message is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed the message - have not added a test, its just single log line. I do want it to create noise if this starts happening (rather than it happening silently) but ideally it never happens.

packages/fdc3-get-agent/src/strategies/HelloHandler.ts Outdated Show resolved Hide resolved
Copy link

464 passed

@robmoffat

This comment was marked as outdated.

@robmoffat
Copy link
Member

I'm seeing a regression running the conformance tests:

Screenshot 2024-12-19 at 13 38 54

I ran it twice and got the same error both times. The fdc3-for-web-impl branch passes everything, so it's something in this PR.

If you want to replicate locally, you'll need to change this line in dummy-desktop-agent.ts:

 const directory = new FDC3_2_1_JSONDirectory();
    //await directory.load('/static/da/appd.json');
    await directory.load('/static/da/local-conformance-2_0.v2.json');   // add this
    const sc = new DemoServerContext(socket, directory);

And you'll need to run the conformance framework, the branch to use is 2_0_fdc3_for_the_web and change the package.json local url to wherever you have your FDC3 project checked out:

 "dependencies": {
    "@kite9/fdc3-get-agent": "file:../../FDC3/packages/fdc3-get-agent",   // probably needs changing for you
    "buffer": "^6.0.3",
    "chai": "^4.3.6",
    "fdc3_1_2": "npm:@finos/fdc3@^1.2.0",
    "fdc3_2_0": "npm:@finos/fdc3@^2.0.0-beta.4",

@kriswest
Copy link
Contributor Author

I'm seeing a regression running the conformance tests:

That is very likely a result of something I've changed as there was quite a lot of work on the private channel lifecycle events. Thanks for the instructions on replicating the test, I'll give it a go and sort that out.

@kriswest

This comment was marked as outdated.

@kriswest
Copy link
Contributor Author

Seeing some new compile errors from a fresh build here:

I can replicate and will fix, my bad.

Actually scratch that, according to git blame all thats changed on the typing there is formatting with prettier, its been this way for 6 months. I don't understand why it's failing now... As the CI checks don't pick up the build failure that could have been happening for some time I suppose... If its just started I don't get why.

Regardless, I can fix it by casting to the target type (HTMLOptionElement) so I've done that...

Copy link

468 passed

Copy link

468 passed

Copy link

468 passed

Copy link

470 passed

Copy link

470 passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants