Skip to content

Conversation

@laileni-aws
Copy link
Contributor

@laileni-aws laileni-aws commented Feb 19, 2025

Problem

  • This will fix Target file doesn't exist or is a directory. issue in unit test generation.
  • If user opens project in workspace mode and try /test then in shared workspaceUtils:
    export function getWorkspaceRelativePath(
    childPath: string,
    override: {
    workspaceFolders?: readonly vscode.WorkspaceFolder[]
    } = {
    workspaceFolders: vscode.workspace.workspaceFolders,
    }
    ): { relativePath: string; workspaceFolder: vscode.WorkspaceFolder } | undefined {
    if (!override.workspaceFolders) {
    return
    }
    for (const folder of override.workspaceFolders) {
    if (isInDirectory(folder.uri.fsPath, childPath)) {
    return { relativePath: path.relative(folder.uri.fsPath, childPath), workspaceFolder: folder }
    }
    }
    }
    returns the files starting from src but UTG does need values from child level.

Solution

Given above function with workspaceFolders as

[
  {
    uri: {
      scheme: "file",
      authority: "",
      path: "/Users/Q/Downloads/TestingUTG/Sample/src",
      query: "",
      fragment: "",
      _formatted: "file:///Users/Q/Downloads/TestingUTG/Sample/src",
      _fsPath: "/Users/Q/Downloads/TestingUTG/Sample/src",
    },
    name: "src",
    index: 0,
  },
  {
    uri: {
      scheme: "file",
      authority: "",
      path: "/Users/laileni/Downloads/TestingUTG/Sample/src/Sample",
      query: "",
      fragment: "",
      _formatted: "file:///Users/Q/Downloads/TestingUTG/Sample/src/Sample",
      _fsPath: "/Users/Q/Downloads/TestingUTG/Sample/src/Sample",
    },
    name: "📦 Sample",
    index: 1,
  },
]

User requires the project/folder with path: "/Users/Q/Downloads/TestingUTG/Sample/src/Sample" but right now this gives the path from "/Users/Q/Downloads/TestingUTG/Sample/src" which incorrectly collects the files and this is causing failures in Unit test generation.

Example:
Expected Payload is

Sample 
    - File A
    - Folder B 
    etc...

but actual payload is

Sample 
   - src
      -- Sample
          --- File A
          --- Folder B 
  • Sort workspace folders by path length (descending) to prioritize deeper paths

TODO:

  • Need to enable this for entire Q

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@laileni-aws laileni-aws marked this pull request as ready for review February 19, 2025 20:49
@laileni-aws laileni-aws requested review from a team as code owners February 19, 2025 20:49
@laileni-aws laileni-aws changed the title fix(amazonq): Updating logic for getWorkspaceRelativePath in shared src fix(amazonq): Updating logic for getWorkspaceRelativePath in shared src for /test Feb 19, 2025
@ashishrp-aws
Copy link
Contributor

Discussed the PR offline to check the conditions, this fix works for test generation.

}
for (const folder of override.workspaceFolders) {
let folders = override.workspaceFolders
if (useCase && useCase === FeatureUseCase.TEST_GENERATION) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels too specific to be put in this shared utility method. Are you planning to update this later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes Will remove this once I get confirmation from Q teams
For now this is required for UTG. I think this is the same case for other features too

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you track this in an issue somewhere so that someone comes back to it. This workspace util is become a monster 😞

}
for (const folder of override.workspaceFolders) {
let folders = override.workspaceFolders
if (useCase && useCase === FeatureUseCase.TEST_GENERATION) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can just do

Suggested change
if (useCase && useCase === FeatureUseCase.TEST_GENERATION) {
if (useCase === FeatureUseCase.TEST_GENERATION) {

@jpinkney-aws jpinkney-aws merged commit 35452cd into aws:master Feb 19, 2025
26 checks passed

for (const file of files) {
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders })
const relativePath = getWorkspaceRelativePath(file.fsPath, { workspaceFolders }, useCase)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already filterFn, why was this special parameter needed?

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.

7 participants