Skip to content

Commit

Permalink
Fixed error messages from raise intent
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Jun 4, 2024
1 parent 9ca4c24 commit d7fa608
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kite9/web-fdc3",
"private": true,
"version": "0.0.17",
"version": "0.0.19",
"workspaces": [
"packages/*"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@kite9/client",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"version": "0.0.17",
"version": "0.0.19",
"scripts": {
"build": "tsc --module es2022",
"clean": "rimraf dist; rimraf cucumber-report.html; rimraf coverage"
Expand Down
2 changes: 1 addition & 1 deletion packages/da-proxy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/da-proxy",
"version": "0.0.17",
"version": "0.0.19",
"files": [
"dist"
],
Expand Down
21 changes: 16 additions & 5 deletions packages/da-proxy/src/intents/DefaultIntentSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ export class DefaultIntentSupport implements IntentSupport {
)
}

private matchAppId(a: AppIdentifier, b: AppIdentifier) {
return (a.appId == b.appId) && ((a.instanceId == null) || a.instanceId == b.instanceId)
private matchAppId(found: AppIdentifier, req: AppIdentifier) {
return (found.appId == req.appId) &&
(((found.instanceId == null) && (req.instanceId == null)) // request was not for a particular instance
||
(found.instanceId == req.instanceId)) // requested exact instance.
}

private filterApps(appIntent: AppIntent, app: AppIdentifier): AppIntent {
Expand All @@ -124,11 +127,19 @@ export class DefaultIntentSupport implements IntentSupport {
if (app) {
// ensure app matches
matched = this.filterApps(matched, app)
}

if (matched.apps.length == 0) {
if (matched.apps.length == 0) {
if (app.instanceId) {
throw new Error(ResolveError.TargetInstanceUnavailable)
} else {
throw new Error(ResolveError.TargetAppUnavailable)
}
}
} else if (matched.apps.length == 0) {
throw new Error(ResolveError.NoAppsFound)
} else if (matched.apps.length == 1) {
}

if (matched.apps.length == 1) {
return this.raiseSpecificIntent(intent, context, matched.apps[0])
} else {
// need to do the intent resolver
Expand Down
93 changes: 44 additions & 49 deletions packages/da-proxy/test/features/raise-intents.feature
Original file line number Diff line number Diff line change
@@ -1,58 +1,53 @@
Feature: Basic Intents Support

Background: Desktop Agent API

Given A Desktop Agent in "api"

And app "chipShop/c1" resolves intent "OrderFood" with result type "void"
And app "chipShop/c2" resolves intent "OrderFood" with result type "channel<fdc3.chips>"
And app "bank/b1" resolves intent "Buy" with context "fdc3.instrument" and result type "fdc3.order"
And app "bank/b1" resolves intent "Sell" with context "fdc3.instrument" and result type "fdc3.order"
And app "travelAgent/t1" resolves intent "BookFlight" with context "fdc3.country" and result type "fdc3.order"

And "instrumentContext" is a "fdc3.instrument" context
And "countryContext" is a "fdc3.country" context

Scenario: Raising An Invalid Intent to the server

When I call "api" with "raiseIntent" with parameters "Buy" and "{instrumentContext}" and "{c1}"
Then "{result}" is an error with message "NoAppsFound"

Scenario: Raising An Invalid Intent to the server

When I call "api" with "raiseIntentForContext" with parameters "{intrumentContext}" and "{t1}"
Then "{result}" is an error with message "NoAppsFound"

Scenario: Raising an intent and invoking the intent resolver when it's not clear which intent is required

Background: Desktop Agent API
Given A Desktop Agent in "api"
And app "chipShop/c1" resolves intent "OrderFood" with result type "void"
And app "chipShop/c2" resolves intent "OrderFood" with result type "channel<fdc3.chips>"
And app "bank/b1" resolves intent "Buy" with context "fdc3.instrument" and result type "fdc3.order"
And app "bank/b1" resolves intent "Sell" with context "fdc3.instrument" and result type "fdc3.order"
And app "travelAgent/t1" resolves intent "BookFlight" with context "fdc3.country" and result type "fdc3.order"
And "instrumentContext" is a "fdc3.instrument" context
And "countryContext" is a "fdc3.country" context

Scenario: Raising An Invalid Intent to the server (no instance)
When I call "api" with "raiseIntent" with parameters "Buy" and "{instrumentContext}" and "{c1}"
Then "{result}" is an error with message "TargetInstanceUnavailable"

Scenario: Raising An Invalid Intent to the server (no app)
When I call "api" with "raiseIntent" with parameters "Buy" and "{instrumentContext}" and "{chipShop}"
Then "{result}" is an error with message "TargetAppUnavailable"

Scenario: Raising An Invalid Intent to the server
When I call "api" with "raiseIntentForContext" with parameters "{intrumentContext}" and "{t1}"
Then "{result}" is an error with message "NoAppsFound"

Scenario: Raising an intent and invoking the intent resolver when it's not clear which intent is required
The intent resolver built in to the tests will just take the first matching application
that would resolve the intent.

When I call "api" with "raiseIntent" with parameters "OrderFood" and "{instrumentContext}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| chipShop | c1 |
When I call "api" with "raiseIntent" with parameters "OrderFood" and "{instrumentContext}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| chipShop | c1 |

Scenario: Raising Intent By Context and invoking the intent resolver when it's not clear which intent is required

Scenario: Raising Intent By Context and invoking the intent resolver when it's not clear which intent is required
The intent resolver built in to the tests will just take the first matching application
that would resolve an intent.

When I call "api" with "raiseIntentForContext" with parameter "{instrumentContext}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| bank | b1 |

Scenario: Raising Intent exactly right, so the resolver isn't required

When I call "api" with "raiseIntent" with parameters "Buy" and "{instrumentContext}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| bank | b1 |

Scenario: Raising Intent By Context exactly right, so the resolver isn't required

When I call "api" with "raiseIntentForContext" with parameters "{countryContext}" and "{t1}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| travelAgent | t1 |
When I call "api" with "raiseIntentForContext" with parameter "{instrumentContext}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| bank | b1 |

Scenario: Raising Intent exactly right, so the resolver isn't required
When I call "api" with "raiseIntent" with parameters "Buy" and "{instrumentContext}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| bank | b1 |

Scenario: Raising Intent By Context exactly right, so the resolver isn't required
When I call "api" with "raiseIntentForContext" with parameters "{countryContext}" and "{t1}"
Then "{result}" is an object with the following contents
| source.appId | source.instanceId |
| travelAgent | t1 |
9 changes: 9 additions & 0 deletions packages/da-proxy/test/step-definitions/intents.steps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Given("app {string} resolves intent {string}", function (this: CustomWorld, appS
intent,
})
this.props[instanceId] = app
this.props[appId] = {
appId
}
})

Given("app {string} resolves intent {string} with result type {string}", function (this: CustomWorld, appStr: string, intent: string, resultType: string) {
Expand All @@ -33,6 +36,9 @@ Given("app {string} resolves intent {string} with result type {string}", functio
resultType
})
this.props[instanceId] = app
this.props[appId] = {
appId
}
})

Given("app {string} resolves intent {string} with context {string}", function (this: CustomWorld, appStr: string, intent: string, context: string) {
Expand All @@ -44,6 +50,9 @@ Given("app {string} resolves intent {string} with context {string}", function (t
context
})
this.props[instanceId] = app
this.props[appId] = {
appId
}
})

Given("app {string} resolves intent {string} with context {string} and result type {string}", function (this: CustomWorld, appStr: string, intent: string, context: string, resultType: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/da-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/da-server",
"version": "0.0.17",
"version": "0.0.19",
"files": [
"dist"
],
Expand Down
49 changes: 26 additions & 23 deletions packages/da-server/test/features/raise-intent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,33 @@ Feature: Raising Intents
And A newly instantiated FDC3 Server
And "App1/a1" is opened
And "App1/b1" is opened
And "App1/b1" sends hello
And "App1/b1" registers an intent listener for "returnBook"
# Scenario: Raising An Intent To A Non-Existent App
# When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "NonExistentApp"
# Then messaging will have outgoing posts
# | msg.type | msg.payload.error | to.instanceId |
# | raiseIntentResponse | TargetAppUnavailable | a1 |
# Scenario: Raising An Intent To A Non-Existent App Instance
# When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "AppZ/b1"
# Then messaging will have outgoing posts
# | msg.type | msg.payload.error | to.instanceId |
# | raiseIntentResponse | TargetInstanceUnavailable | a1 |
# Scenario: Raising An Intent To A Running App
# When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "App1/b1"
# Then messaging will have outgoing posts
# | msg.type | msg.payload.intent | to.instanceId |
# | raiseIntentRequest | returnBook | b1 |
# Scenario: Raising An Intent To A Non-Running App
# When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "libraryApp"
# And "libraryApp/0" is opened
# And "libraryApp/0" registers an intent listener for "returnBook"
# Then messaging will have outgoing posts
# | msg.type | msg.payload.intent | to.instanceId | to.appId | msg.payload.context.type |
# | raiseIntentRequest | returnBook | 0 | libraryApp | fdc3.book |

Scenario: Raising An Intent To A Non-Existent App
When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "NonExistentApp"
Then messaging will have outgoing posts
| msg.type | msg.payload.error | to.instanceId |
| raiseIntentResponse | TargetAppUnavailable | a1 |

Scenario: Raising An Intent To A Non-Existent App Instance
When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "AppZ/b1"
Then messaging will have outgoing posts
| msg.type | msg.payload.error | to.instanceId |
| raiseIntentResponse | TargetInstanceUnavailable | a1 |

Scenario: Raising An Intent To A Running App
When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "App1/b1"
Then messaging will have outgoing posts
| msg.type | msg.payload.intent | to.instanceId |
| raiseIntentRequest | returnBook | b1 |

Scenario: Raising An Intent To A Non-Running App
When "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "libraryApp"
And "libraryApp/0" is opened
And "libraryApp/0" registers an intent listener for "returnBook"
Then messaging will have outgoing posts
| msg.type | msg.payload.intent | to.instanceId | to.appId | msg.payload.context.type |
| raiseIntentRequest | returnBook | 0 | libraryApp | fdc3.book |

Scenario: Raising an Intent to a Non-Existent App Instance
And "App1/a1" raises an intent for "returnBook" with contextType "fdc3.book" on app "unusedApp/u1"
Expand Down
2 changes: 1 addition & 1 deletion packages/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@kite9/demo",
"private": true,
"version": "0.0.17",
"version": "0.0.19",
"scripts": {
"dev": "nodemon -w src/server -x tsx src/server/main.ts",
"start": "NODE_ENV=production tsx src/server/main.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/fdc3-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kite9/fdc3-common",
"version": "0.0.17",
"version": "0.0.19",
"files": [
"dist"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/fdc3-workbench/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fdc3-workbench",
"version": "0.0.17",
"version": "0.0.19",
"private": true,
"homepage": ".",
"license": "Apache-2.0",
Expand Down

0 comments on commit d7fa608

Please sign in to comment.