Skip to content

Conversation

@agrasth
Copy link
Contributor

@agrasth agrasth commented Dec 2, 2025

  • All tests passed. If this feature is not already covered by the tests, I added new tests.
  • All static analysis checks passed.
  • This pull request is on the master branch.
  • I used gofmt for formatting the code before submitting the pull request.

Fix: --include Flag Ignored When Using Spec Files in Search Command

Description

This PR fixes a bug where the --include flag is ignored when using a spec file with the jf rt search command, causing all fields to be returned instead of only the fields specified in the --include flag.

Issue

When using the search command with a spec file and the --include flag, the result returns all the fields instead of returning only the fields specified in the --include flag.

Steps to Reproduce

  1. Create a spec file (spec.json):
{
  "files": [
    {
      "aql": {
        "items.find": {
          "repo": "npm-remote-cache"
        }
      }
    }
  ]
}
  1. Execute the command:
jf rt search --spec=spec.json --include="name;repo" --limit=3
  1. Observe that all fields are returned instead of only the specified fields.

Expected Behavior

Based on the documentation, when the --include flag is used, only the fields specified in the flag should be returned (along with path which is always included, and props which appears to always be included in the response).

Impact

Customers cannot use the --include functionality when they use a spec file, forcing them to either:

  • Not use spec files (workaround: jf rt search <repo_name> --include="<field_names>")
  • Use AQL queries directly without JFrog CLI
  • Parse and filter the full response themselves

Root Cause

The OverrideFieldsIfSet function in three locations was missing the override for the include field:

  • jfrog-cli-core/common/cliutils/spec.go
  • jfrog-cli/utils/cliutils/utils.go
  • jfrog-cli-core/plugins/common/config.go

While the function properly overrides fields like exclusions, props, transitive, etc., it was not handling the include field. Additionally, since include is a private field in the File struct, a setter method was needed to modify it from outside the package.

Before the Fix

Command:

jf rt search --spec=spec.json --include="name;repo" --limit=3

Response (ALL fields returned - BUG):

[
  {
    "path": "npm-remote-cache/.npm/send/package.json",
    "type": "file",
    "size": 147586,
    "created": "2025-03-31T15:04:41.156Z",
    "modified": "2025-03-27T01:39:15.000Z",
    "sha1": "2208b57f076a5b5baefbcdb3d7c9f9ce8f068407",
    "sha256": "8d6764b2ff707e018af681f5bb644693aea293523fdd4e0e18f6e48f52563652",
    "md5": "171183574353643ddda46696efb4f963",
    "props": {
      "artifactory.internal.etag": [
        "W/\"171183574353643ddda46696efb4f963\""
      ]
    }
  },
  {
    "path": "npm-remote-cache/.npm/jfrog-midgard/package.json",
    "type": "file",
    "size": 3064,
    "created": "2025-03-31T15:04:42.388Z",
    "modified": "2022-05-06T13:09:09.000Z",
    "sha1": "094abc56334ba4e15519e32e8309e99042bae49c",
    "sha256": "b0d8802958bb16a7c24bbcc231f91d27932ca6f812796eee9c5b4ea136176c6d",
    "md5": "e247404ece26afdc9cae84ae25ee6f51",
    "props": {
      "artifactory.internal.etag": [
        "W/\"e247404ece26afdc9cae84ae25ee6f51\""
      ]
    }
  },
  {
    "path": "npm-remote-cache/.npm/debug/package.json",
    "type": "file",
    "size": 195840,
    "created": "2025-03-31T15:04:42.797Z",
    "modified": "2025-09-13T17:25:21.000Z",
    "sha1": "aa0be9552dd92666cd055b447d59d572ba6aecf6",
    "sha256": "7cd3d7bd97fdfb4af9fb90023decb619a19811c5e5aae94c3b66935cce37abae",
    "md5": "11050952da2ca49e2571ebcd3dfd554e",
    "props": {
      "artifactory.internal.etag": [
        "W/\"11050952da2ca49e2571ebcd3dfd554e\""
      ],
      "jf.origin.remote.path": [
        "https://registry.npmjs.org/debug"
      ]
    }
  }
]

After the Fix

Command:

jf rt search --spec=spec.json --include="name;repo" --limit=3

Response (Limited fields only - FIXED):

[
  {
    "path": "npm-remote-cache/.npm/send/package.json",
    "props": {
      "artifactory.internal.etag": [
        "W/\"171183574353643ddda46696efb4f963\""
      ]
    }
  },
  {
    "path": "npm-remote-cache/.npm/jfrog-midgard/package.json",
    "props": {
      "artifactory.internal.etag": [
        "W/\"e247404ece26afdc9cae84ae25ee6f51\""
      ]
    }
  },
  {
    "path": "npm-remote-cache/.npm/debug/package.json",
    "props": {
      "artifactory.internal.etag": [
        "W/\"11050952da2ca49e2571ebcd3dfd554e\""
      ],
      "jf.origin.remote.path": [
        "https://registry.npmjs.org/debug"
      ]
    }
  }
]

Additional Test with --include="path"

Command:

jf rt search --spec=spec.json --include="path" --limit=2

Before (ALL fields returned):

[
  {
    "path": "npm-remote-cache/.npm/send/package.json",
    "type": "file",
    "size": 147586,
    "created": "2025-03-31T15:04:41.156Z",
    "modified": "2025-03-27T01:39:15.000Z",
    "sha1": "2208b57f076a5b5baefbcdb3d7c9f9ce8f068407",
    "sha256": "8d6764b2ff707e018af681f5bb644693aea293523fdd4e0e18f6e48f52563652",
    "md5": "171183574353643ddda46696efb4f963",
    "props": { ... }
  },
  ...
]

After (Limited fields only):

[
  {
    "path": "npm-remote-cache/.npm/send/package.json",
    "props": {
      "artifactory.internal.etag": [
        "W/\"171183574353643ddda46696efb4f963\""
      ]
    }
  },
  {
    "path": "npm-remote-cache/.npm/jfrog-midgard/package.json",
    "props": {
      "artifactory.internal.etag": [
        "W/\"e247404ece26afdc9cae84ae25ee6f51\""
      ]
    }
  }
]

Verification of Workaround (No Spec File)

Command:

jf rt search "npm-remote-cache/*" --include="path" --limit=2

Response (Already working correctly):

[
  {
    "path": "npm-remote-cache/.npm/send/package.json",
    "props": {
      "artifactory.internal.etag": [
        "W/\"171183574353643ddda46696efb4f963\""
      ]
    }
  },
  {
    "path": "npm-remote-cache/.npm/jfrog-midgard/package.json",
    "props": {
      "artifactory.internal.etag": [
        "W/\"e247404ece26afdc9cae84ae25ee6f51\""
      ]
    }
  }
]

Related PRs:

@agrasth agrasth added bug Something isn't working safe-to-test labels Dec 2, 2025
@reshmifrog reshmifrog self-requested a review December 2, 2025 07:16
@reshmifrog
Copy link
Contributor

Can you please check why the include field is unexported while other fields like exclusions are not?
Is it possible to make it exported and use , if yes then we do not need to use any setters.

@agrasth agrasth force-pushed the include-flag-fix branch 2 times, most recently from fbf4ed9 to 4171d50 Compare December 2, 2025 09:02
Make Include field public to allow JSON unmarshaling from spec files and direct field access.
This is cleaner and more consistent with other fields like Exclusions.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 2, 2025

👍 Frogbot scanned this pull request and did not find any new security issues.


@agrasth agrasth merged commit 3cc5f34 into jfrog:master Dec 10, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working safe-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants