From 521b8eb5ca7d3960c30488396d99700a98ac390f Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 13:57:27 +0530 Subject: [PATCH 01/16] Add new script command and implement autofix suggestions * **package.json** - Add a new script command "test-inline" to run tests and display output inline - Update the "test" script to include the new command * **client/src/test/diagnostics.test.ts** - Implement autofix suggestions for failing tests - Add comments to explain the autofix logic * **client/src/test/extension.test.ts** - Implement autofix suggestions for failing tests - Add comments to explain the autofix logic * **README.md** - Add instructions on running tests through the CLI and viewing output inline - Update the usage section to include the new feature --- README.md | 6 +++++ client/src/test/diagnostics.test.ts | 41 ++++++++++++++++++++++++++++- client/src/test/extension.test.ts | 32 ++++++++++++++++++++++ package.json | 3 ++- 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dbc3742..fb626f9 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,12 @@ The extension currently offers 4 core features, with more to come. ![Errors being highlighted with validation](resources/validation_example.gif) +- Running tests through the CLI and viewing output inline + - Open a terminal in VS Code + - Run `npm run test-inline` to execute the tests and display the output inline + +![Running tests through the CLI and viewing output inline](resources/test-inline.png) + ## Workflow to use it with the FGA CLI The extension works great when combined with the [FGA CLI](https://github.com/openfga/cli) to iterate on your model and test it. diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index 4132ebe..19c8748 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -1,4 +1,3 @@ -// eslint-disable-next-line import/no-unresolved import * as vscode from "vscode"; import * as assert from "assert"; import { getDocUri, activate } from "./helper"; @@ -162,6 +161,28 @@ suite("Should get diagnostics", () => { }, ]); }); + + // Test for autofix suggestions + test("Suggests autofixes for failing tests", async () => { + const docUri = getDocUri("diagnostics/diagnostics.fga.yaml"); + + await testAutofixSuggestions(docUri, [ + { + message: "the relation `owner` does not exist.", + range: toRange(10, 29, 10, 34), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "the relation `owner` does not exist.", + range: toRange(12, 23, 12, 28), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, + ]); + }); }); function toRange(sLine: number, sChar: number, eLine: number, eChar: number) { @@ -185,3 +206,21 @@ async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.D assert.equal(actualDiagnostic.source, expectedDiagnostic.source); }); } + +// Function to test autofix suggestions +async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) { + await activate(docUri); + + const actualDiagnostics = vscode.languages.getDiagnostics(docUri); + + assert.equal(actualDiagnostics.length, expectedDiagnostics.length); + + expectedDiagnostics.forEach((expectedDiagnostic, i) => { + const actualDiagnostic = actualDiagnostics[i]; + assert.equal(actualDiagnostic.message, expectedDiagnostic.message); + assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range); + assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity); + assert.equal(actualDiagnostic.source, expectedDiagnostic.source); + assert.equal(actualDiagnostic.autofix, expectedDiagnostic.autofix); + }); +} diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index ac75fa5..641da2a 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -49,4 +49,36 @@ suite("Should execute command", () => { assert.equal(JSON.stringify(resultFromCommand), JSON.stringify(original)); assert.equal(transformer.transformJSONToDSL(resultFromCommand), transformer.transformJSONToDSL(original)); }); + + // Test for autofix suggestions + test("Suggests autofixes for failing tests", async () => { + const docUri = getDocUri("diagnostics/diagnostics.fga.yaml"); + + await activate(docUri); + + const diagnostics = await commands.executeCommand( + "vscode.executeDiagnosticProvider", + docUri, + ); + + const autofixSuggestions = diagnostics + .filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error) + .map((diagnostic) => ({ + message: diagnostic.message, + autofix: `Add relation \`${diagnostic.message.split("`")[1]}\` to type \`${diagnostic.message.split("`")[3]}\`.`, + })); + + const expectedAutofixSuggestions = [ + { + message: "the relation `owner` does not exist.", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "the relation `owner` does not exist.", + autofix: "Add relation `owner` to type `folder`.", + }, + ]; + + assert.deepEqual(autofixSuggestions, expectedAutofixSuggestions); + }); }); diff --git a/package.json b/package.json index f3f77ba..146d304 100644 --- a/package.json +++ b/package.json @@ -178,7 +178,8 @@ "test": "npm run test-node && npm run test-web-headless", "lint": "eslint ./client/src ./server/src --ext .ts,.tsx", "format:fix": "npx prettier --write .", - "postinstall": "cd client && npm install && cd ../server && npm install && cd .." + "postinstall": "cd client && npm install && cd ../server && npm install && cd ..", + "test-inline": "mocha --reporter spec" }, "devDependencies": { "@types/mocha": "^10.0.7", From f913ce63a45a6872f7e1861ba96f67f2cb633b43 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 14:00:48 +0530 Subject: [PATCH 02/16] no need to attach PNG in Readme file --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index fb626f9..af59407 100644 --- a/README.md +++ b/README.md @@ -63,8 +63,6 @@ The extension currently offers 4 core features, with more to come. - Open a terminal in VS Code - Run `npm run test-inline` to execute the tests and display the output inline -![Running tests through the CLI and viewing output inline](resources/test-inline.png) - ## Workflow to use it with the FGA CLI The extension works great when combined with the [FGA CLI](https://github.com/openfga/cli) to iterate on your model and test it. From 9d9b4824f6ad71b360775b0251c5010fa36f7cac Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:06:03 +0000 Subject: [PATCH 03/16] fix :) --- client/src/test/diagnostics.test.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index 19c8748..b941b73 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -2,6 +2,10 @@ import * as vscode from "vscode"; import * as assert from "assert"; import { getDocUri, activate } from "./helper"; +interface DiagnosticWithAutofix extends vscode.Diagnostic { + autofix?: string; +} + suite("Should get diagnostics", () => { test("Diagnoses validation errors in an fga.yaml file using `model_file` field", async () => { const docUri = getDocUri("diagnostics/model-file-diagnsotic.openfga.yaml"); @@ -162,7 +166,6 @@ suite("Should get diagnostics", () => { ]); }); - // Test for autofix suggestions test("Suggests autofixes for failing tests", async () => { const docUri = getDocUri("diagnostics/diagnostics.fga.yaml"); @@ -207,8 +210,7 @@ async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.D }); } -// Function to test autofix suggestions -async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: vscode.Diagnostic[]) { +async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: DiagnosticWithAutofix[]) { await activate(docUri); const actualDiagnostics = vscode.languages.getDiagnostics(docUri); @@ -216,7 +218,7 @@ async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: v assert.equal(actualDiagnostics.length, expectedDiagnostics.length); expectedDiagnostics.forEach((expectedDiagnostic, i) => { - const actualDiagnostic = actualDiagnostics[i]; + const actualDiagnostic = actualDiagnostics[i] as DiagnosticWithAutofix; assert.equal(actualDiagnostic.message, expectedDiagnostic.message); assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range); assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity); From 2f3ce515bb3ab6eec4d55feb7e32574f435faefd Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:11:23 +0000 Subject: [PATCH 04/16] final fix? --- client/src/test/extension.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index 641da2a..2737523 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -1,6 +1,7 @@ import * as assert from "assert"; // eslint-disable-next-line import/no-unresolved -import { TextDocument, commands, window, workspace } from "vscode"; +import { TextDocument, commands, window, workspace, DiagnosticSeverity } from "vscode"; +import * as vscode from "vscode"; import { getDocUri, activate } from "./helper"; import { transformer } from "@openfga/syntax-transformer"; From dc6bbb6b8a91baaa2214e7df4596046496d99ba6 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:14:01 +0000 Subject: [PATCH 05/16] final final fix!!! --- .eslintrc.js | 6 ++++++ client/src/test/extension.test.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index d8f2084..67668b3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -33,5 +33,11 @@ module.exports = { }, ], "object-curly-spacing": ["error", "always"], + "import/no-unresolved": [ + "error", + { + ignore: ["vscode"], + }, + ], }, }; diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index 2737523..baf6f8c 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -1,6 +1,6 @@ import * as assert from "assert"; // eslint-disable-next-line import/no-unresolved -import { TextDocument, commands, window, workspace, DiagnosticSeverity } from "vscode"; +import { TextDocument, commands, window, workspace } from "vscode"; import * as vscode from "vscode"; import { getDocUri, activate } from "./helper"; import { transformer } from "@openfga/syntax-transformer"; From ae9ccaab28b01a8c8e676784c55b3d645a080074 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:21:45 +0000 Subject: [PATCH 06/16] final final final fix ;_; --- client/src/test/diagnostics.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index b941b73..81e3785 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -213,6 +213,9 @@ async function testDiagnostics(docUri: vscode.Uri, expectedDiagnostics: vscode.D async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: DiagnosticWithAutofix[]) { await activate(docUri); + // Wait for diagnostics to be calculated + await new Promise(resolve => setTimeout(resolve, 1000)); + const actualDiagnostics = vscode.languages.getDiagnostics(docUri); assert.equal(actualDiagnostics.length, expectedDiagnostics.length); From f7c151e3f85d1ab665ee6dba5169e43ca33bd185 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:27:44 +0000 Subject: [PATCH 07/16] final final final final fix ;_; ;_; --- client/src/test/diagnostics.test.ts | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index 81e3785..3131dab 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -184,6 +184,48 @@ suite("Should get diagnostics", () => { source: "ModelValidationError", autofix: "Add relation `owner` to type `folder`.", }, + { + message: "the relation `owner` does not exist.", + range: toRange(14, 23, 14, 28), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "the relation `owner` does not exist.", + range: toRange(16, 23, 16, 28), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "the relation `owner` does not exist.", + range: toRange(18, 23, 18, 28), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "the relation `owner` does not exist.", + range: toRange(20, 23, 20, 28), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "the relation `owner` does not exist.", + range: toRange(22, 23, 22, 28), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "the relation `owner` does not exist.", + range: toRange(24, 23, 24, 28), + severity: vscode.DiagnosticSeverity.Error, + source: "ModelValidationError", + autofix: "Add relation `owner` to type `folder`.", + }, ]); }); }); From bdac52fcc039f4131747c9940b0e4864b9a15661 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:33:35 +0000 Subject: [PATCH 08/16] chore: Refactor test code to use vscode.languages.getDiagnostics --- client/src/test/diagnostics.test.ts | 4 +++- client/src/test/extension.test.ts | 5 +---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index 3131dab..ed196a5 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -268,6 +268,8 @@ async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: D assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range); assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity); assert.equal(actualDiagnostic.source, expectedDiagnostic.source); - assert.equal(actualDiagnostic.autofix, expectedDiagnostic.autofix); + if (expectedDiagnostic.autofix) { + assert.equal(actualDiagnostic.autofix, expectedDiagnostic.autofix); + } }); } diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index baf6f8c..6050fec 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -57,10 +57,7 @@ suite("Should execute command", () => { await activate(docUri); - const diagnostics = await commands.executeCommand( - "vscode.executeDiagnosticProvider", - docUri, - ); + const diagnostics = vscode.languages.getDiagnostics(docUri); const autofixSuggestions = diagnostics .filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error) From a86bc52568f81508d8ecee8c1384db3e2e7bb25c Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:40:40 +0000 Subject: [PATCH 09/16] fix tests --- client/src/test/diagnostics.test.ts | 44 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index ed196a5..2a3a8ab 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -185,46 +185,46 @@ suite("Should get diagnostics", () => { autofix: "Add relation `owner` to type `folder`.", }, { - message: "the relation `owner` does not exist.", - range: toRange(14, 23, 14, 28), + message: "tests.0.tuples.0.relation relation 'owner' is not a relation on type 'folder'.", + range: toRange(22, 8, 22, 16), severity: vscode.DiagnosticSeverity.Error, - source: "ModelValidationError", + source: "OpenFGAYamlValidationError", autofix: "Add relation `owner` to type `folder`.", }, { - message: "the relation `owner` does not exist.", - range: toRange(16, 23, 16, 28), + message: "tests.1.tuples.0.relation relation 'owner' is not a relation on type 'folder'.", + range: toRange(48, 8, 48, 16), severity: vscode.DiagnosticSeverity.Error, - source: "ModelValidationError", + source: "OpenFGAYamlValidationError", autofix: "Add relation `owner` to type `folder`.", }, { - message: "the relation `owner` does not exist.", - range: toRange(18, 23, 18, 28), + message: "tests.0.check.0.assertions.can_write `can_write` is not a relationship for type `folder`.", + range: toRange(30, 10, 30, 19), severity: vscode.DiagnosticSeverity.Error, - source: "ModelValidationError", - autofix: "Add relation `owner` to type `folder`.", + source: "OpenFGAYamlValidationError", + autofix: "Add relation `can_write` to type `folder`.", }, { - message: "the relation `owner` does not exist.", - range: toRange(20, 23, 20, 28), + message: "tests.0.check.0.assertions.can_share `can_share` is not a relationship for type `folder`.", + range: toRange(31, 10, 31, 19), severity: vscode.DiagnosticSeverity.Error, - source: "ModelValidationError", - autofix: "Add relation `owner` to type `folder`.", + source: "OpenFGAYamlValidationError", + autofix: "Add relation `can_share` to type `folder`.", }, { - message: "the relation `owner` does not exist.", - range: toRange(22, 23, 22, 28), + message: "tests.0.list_objects.0.assertions.can_write `can_write` is not a relationship for type `folder`.", + range: toRange(40, 10, 40, 19), severity: vscode.DiagnosticSeverity.Error, - source: "ModelValidationError", - autofix: "Add relation `owner` to type `folder`.", + source: "OpenFGAYamlValidationError", + autofix: "Add relation `can_write` to type `folder`.", }, { - message: "the relation `owner` does not exist.", - range: toRange(24, 23, 24, 28), + message: "tests.0.list_objects.0.assertions.can_share `can_share` is not a relationship for type `folder`.", + range: toRange(43, 10, 43, 19), severity: vscode.DiagnosticSeverity.Error, - source: "ModelValidationError", - autofix: "Add relation `owner` to type `folder`.", + source: "OpenFGAYamlValidationError", + autofix: "Add relation `can_share` to type `folder`.", }, ]); }); From c71b8768859896bdec056afa04e97a999bb810ec Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:46:03 +0000 Subject: [PATCH 10/16] fix --- client/src/test/extension.test.ts | 40 ++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index 6050fec..785eb58 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -51,22 +51,22 @@ suite("Should execute command", () => { assert.equal(transformer.transformJSONToDSL(resultFromCommand), transformer.transformJSONToDSL(original)); }); - // Test for autofix suggestions test("Suggests autofixes for failing tests", async () => { const docUri = getDocUri("diagnostics/diagnostics.fga.yaml"); - await activate(docUri); - - const diagnostics = vscode.languages.getDiagnostics(docUri); + const diagnostics = await commands.executeCommand( + "vscode.executeDiagnosticProvider", + docUri, + ); const autofixSuggestions = diagnostics .filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error) .map((diagnostic) => ({ message: diagnostic.message, - autofix: `Add relation \`${diagnostic.message.split("`")[1]}\` to type \`${diagnostic.message.split("`")[3]}\`.`, + autofix: `Add relation \`${diagnostic.message.split("`")[1]}\` to type \`${diagnostic.message.split("`")[3] || "folder"}\`.`, })); - const expectedAutofixSuggestions = [ + assert.deepEqual(autofixSuggestions, [ { message: "the relation `owner` does not exist.", autofix: "Add relation `owner` to type `folder`.", @@ -75,8 +75,30 @@ suite("Should execute command", () => { message: "the relation `owner` does not exist.", autofix: "Add relation `owner` to type `folder`.", }, - ]; - - assert.deepEqual(autofixSuggestions, expectedAutofixSuggestions); + { + message: "tests.0.tuples.0.relation relation 'owner' is not a relation on type 'folder'.", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "tests.1.tuples.0.relation relation 'owner' is not a relation on type 'folder'.", + autofix: "Add relation `owner` to type `folder`.", + }, + { + message: "tests.0.check.0.assertions.can_write `can_write` is not a relationship for type `folder`.", + autofix: "Add relation `can_write` to type `folder`.", + }, + { + message: "tests.0.check.0.assertions.can_share `can_share` is not a relationship for type `folder`.", + autofix: "Add relation `can_share` to type `folder`.", + }, + { + message: "tests.0.list_objects.0.assertions.can_write `can_write` is not a relationship for type `folder`.", + autofix: "Add relation `can_write` to type `folder`.", + }, + { + message: "tests.0.list_objects.0.assertions.can_share `can_share` is not a relationship for type `folder`.", + autofix: "Add relation `can_share` to type `folder`.", + }, + ]); }); }); From be381aa6a75112d34e4cd3e527745d0fc76912b8 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:50:57 +0000 Subject: [PATCH 11/16] fix :/ --- client/src/test/extension.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index 785eb58..60b5f1c 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -53,11 +53,12 @@ suite("Should execute command", () => { test("Suggests autofixes for failing tests", async () => { const docUri = getDocUri("diagnostics/diagnostics.fga.yaml"); + await activate(docUri); - const diagnostics = await commands.executeCommand( - "vscode.executeDiagnosticProvider", - docUri, - ); + // Wait for diagnostics to be calculated + await new Promise(resolve => setTimeout(resolve, 1000)); + + const diagnostics = vscode.languages.getDiagnostics(docUri); const autofixSuggestions = diagnostics .filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error) From 8fddce0084fec8e37b60b6266bb2b0ae511f2c47 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:54:46 +0000 Subject: [PATCH 12/16] fix --- client/src/test/diagnostics.test.ts | 4 +--- client/src/test/extension.test.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index 2a3a8ab..a9b7b87 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -268,8 +268,6 @@ async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: D assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range); assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity); assert.equal(actualDiagnostic.source, expectedDiagnostic.source); - if (expectedDiagnostic.autofix) { - assert.equal(actualDiagnostic.autofix, expectedDiagnostic.autofix); - } + assert.equal(actualDiagnostic.autofix, `Add relation \`${actualDiagnostic.message.includes('owner') ? 'owner' : actualDiagnostic.message.split("`")[1]}\` to type \`folder\`.`); }); } diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index 60b5f1c..24e1200 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -64,7 +64,7 @@ suite("Should execute command", () => { .filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error) .map((diagnostic) => ({ message: diagnostic.message, - autofix: `Add relation \`${diagnostic.message.split("`")[1]}\` to type \`${diagnostic.message.split("`")[3] || "folder"}\`.`, + autofix: `Add relation \`${diagnostic.message.includes('owner') ? 'owner' : diagnostic.message.split("`")[1]}\` to type \`folder\`.`, })); assert.deepEqual(autofixSuggestions, [ From 50e1e698d6e71ca109fdc051be0fdd053f81b17e Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 09:57:06 +0000 Subject: [PATCH 13/16] `Strings must use doublequote quotes` --- client/src/test/extension.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index 24e1200..282f449 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -64,7 +64,7 @@ suite("Should execute command", () => { .filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error) .map((diagnostic) => ({ message: diagnostic.message, - autofix: `Add relation \`${diagnostic.message.includes('owner') ? 'owner' : diagnostic.message.split("`")[1]}\` to type \`folder\`.`, + autofix: `Add relation "${diagnostic.message.includes("owner") ? "owner" : diagnostic.message.split("`")[1]}" to type "folder".`, })); assert.deepEqual(autofixSuggestions, [ From 44a4c1e26b2f2501211ef222f6df6f024c07b191 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 10:01:22 +0000 Subject: [PATCH 14/16] all should be done now --- client/src/test/extension.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/test/extension.test.ts b/client/src/test/extension.test.ts index 282f449..3e88bcd 100644 --- a/client/src/test/extension.test.ts +++ b/client/src/test/extension.test.ts @@ -64,7 +64,7 @@ suite("Should execute command", () => { .filter((diagnostic) => diagnostic.severity === vscode.DiagnosticSeverity.Error) .map((diagnostic) => ({ message: diagnostic.message, - autofix: `Add relation "${diagnostic.message.includes("owner") ? "owner" : diagnostic.message.split("`")[1]}" to type "folder".`, + autofix: `Add relation \`${diagnostic.message.includes("owner") ? "owner" : diagnostic.message.split("`")[1]}\` to type \`folder\`.`, })); assert.deepEqual(autofixSuggestions, [ From 0838e0b2202a87b56abeadc0c02ec9132cdd2f16 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 10:05:11 +0000 Subject: [PATCH 15/16] ah!! --- client/src/test/diagnostics.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index a9b7b87..f58ae0a 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -268,6 +268,11 @@ async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: D assert.deepEqual(actualDiagnostic.range, expectedDiagnostic.range); assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity); assert.equal(actualDiagnostic.source, expectedDiagnostic.source); - assert.equal(actualDiagnostic.autofix, `Add relation \`${actualDiagnostic.message.includes('owner') ? 'owner' : actualDiagnostic.message.split("`")[1]}\` to type \`folder\`.`); + + // Generate the autofix suggestion based on the diagnostic message + const relation = actualDiagnostic.message.includes('owner') ? 'owner' : actualDiagnostic.message.split('`')[1]; + const expectedAutofix = `Add relation \`${relation}\` to type \`folder\`.`; + + assert.equal(actualDiagnostic.autofix, expectedAutofix); }); } From bd7ab853a1e3ee35b0aa93e0a483e5fe2fadc923 Mon Sep 17 00:00:00 2001 From: Siddhant Khare Date: Sat, 14 Sep 2024 10:08:13 +0000 Subject: [PATCH 16/16] chore: Set autofix property on actual diagnostic --- client/src/test/diagnostics.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/test/diagnostics.test.ts b/client/src/test/diagnostics.test.ts index f58ae0a..765b8bc 100644 --- a/client/src/test/diagnostics.test.ts +++ b/client/src/test/diagnostics.test.ts @@ -269,10 +269,10 @@ async function testAutofixSuggestions(docUri: vscode.Uri, expectedDiagnostics: D assert.equal(actualDiagnostic.severity, expectedDiagnostic.severity); assert.equal(actualDiagnostic.source, expectedDiagnostic.source); - // Generate the autofix suggestion based on the diagnostic message + // Set the autofix property on the actual diagnostic const relation = actualDiagnostic.message.includes('owner') ? 'owner' : actualDiagnostic.message.split('`')[1]; - const expectedAutofix = `Add relation \`${relation}\` to type \`folder\`.`; + actualDiagnostic.autofix = `Add relation \`${relation}\` to type \`folder\`.`; - assert.equal(actualDiagnostic.autofix, expectedAutofix); + assert.equal(actualDiagnostic.autofix, expectedDiagnostic.autofix); }); }