Skip to content

Commit

Permalink
Fixed findIntents / findIntentsByContext tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed May 15, 2024
1 parent 32af608 commit a39bd0f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 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.16",
"version": "0.0.17",
"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.16",
"version": "0.0.17",
"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.16",
"version": "0.0.17",
"files": [
"dist"
],
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.16",
"version": "0.0.17",
"files": [
"dist"
],
Expand Down
26 changes: 14 additions & 12 deletions packages/da-server/src/directory/BasicDirectory.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Directory, DirectoryApp, DirectoryIntent } from "./DirectoryInterface"

export function genericResultTypeSame(a: string | undefined, b: string | undefined) {
if (a == b) {
return true;
} else if ((a == undefined) || (b == undefined)) {
return true;
} else if (a.startsWith("channel<") && b == "channel") {
return true;
} else if (b.startsWith("channel<") && a == "channel") {
return true;
export function genericResultTypeSame(real: string | undefined, required: string | undefined) {
if (required == undefined) {
return true
} else if (real == required) {
return true
} else if (real == undefined) {
return false // required is not undefined, so asking for something
} else if (real.startsWith("channel<") && required == "channel") {
return true
} else {
return false;
return false
}
}

Expand All @@ -26,9 +26,11 @@ export class BasicDirectory implements Directory {
}

private intentMatches(i: DirectoryIntent, contextType: string | undefined, intentName: string | undefined, resultType: string | undefined): boolean {
return ((intentName == undefined) || (i.intentName == intentName)) &&
((contextType == undefined) || (i.contexts == null) || (i.contexts.includes(contextType))) &&
const out = ((intentName == undefined) || (i.intentName == intentName)) &&
((contextType == undefined) || (i.contexts.includes(contextType))) &&
(genericResultTypeSame(i.resultType, resultType))
console.log(`Intent ${JSON.stringify(i)} matches ? ${out}}"`)
return out
}

private retrieveIntentsForApp(a: DirectoryApp): DirectoryIntent[] {
Expand Down
37 changes: 22 additions & 15 deletions packages/da-server/src/handlers/IntentHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,27 @@ export class IntentHandler implements MessageHandler {
// TODO: Add result type
const { context } = r.payload

const apps1 = this.directory.retrieveIntents(context?.type, undefined, undefined).map(di => {
return {
intent: {
name: di.intentName,
displayName: di.displayName
},
apps: [
{
appId: di.appId
}
]
} as AppIntent
const apps1 = this.directory.retrieveIntents(context?.type, undefined, undefined)

// fold apps so same intents aren't duplicated
const apps2: AppIntent[] = []
apps1.forEach(a1 => {
const existing = apps2.find(a2 => a2.intent.name == a1.intentName)
if (existing) {
existing.apps.push({ appId: a1.appId })
} else {
apps2.push({
intent: {
name: a1.intentName,
displayName: a1.displayName ?? a1.intentName
},
apps: [
{
appId: a1.appId
}
]
})
}
})

const out = {
Expand All @@ -247,9 +256,7 @@ export class IntentHandler implements MessageHandler {
},
type: "findIntentsByContextResponse",
payload: {
appIntents: [
...apps1
]
appIntents: apps2
}
} as FindIntentsByContextAgentResponse

Expand Down
6 changes: 3 additions & 3 deletions packages/da-server/test/features/find-intent.feature
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ Feature: Find Intent API
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | msg.payload.appIntent.apps[0].appId | to.instanceId |
| findIntentResponse | streamBook | 1 | libraryApp | a1 |

Scenario: Successful Find Intents Request With an untyped Channel
Scenario: Unsuccessful Find Intents Request With an untyped Channel
When "App1/a1" finds intents with intent "streamAny" and contextType "{empty}" and result type "channel<spurious>"
Then messaging will have outgoing posts
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length | msg.payload.appIntent.apps[0].appId | to.instanceId |
| findIntentResponse | streamAny | 1 | libraryApp | a1 |
| msg.type | msg.payload.appIntent.intent.name | msg.payload.appIntent.apps.length |
| findIntentResponse | streamAny | 0 |

Scenario: Find Intent includes results for a running app with intent listener
When "App1/a1" finds intents with intent "returnBook" and contextType "fdc3.book" and result type "{empty}"
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.16",
"version": "0.0.17",
"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.16",
"version": "0.0.17",
"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.16",
"version": "0.0.17",
"private": true,
"homepage": ".",
"license": "Apache-2.0",
Expand Down

0 comments on commit a39bd0f

Please sign in to comment.