Skip to content

fix(analyze): honor offline mode for sharing#18

Open
aqilaziz wants to merge 4 commits into
optiqor:mainfrom
aqilaziz:fix-offline-share-mode
Open

fix(analyze): honor offline mode for sharing#18
aqilaziz wants to merge 4 commits into
optiqor:mainfrom
aqilaziz:fix-offline-share-mode

Conversation

@aqilaziz
Copy link
Copy Markdown

Summary

  • honor --offline and OPTIQOR_OFFLINE=1 before running the --share upload path
  • print warning: --share is ignored in --offline mode and exit successfully when sharing is skipped
  • document the offline env override in help/README and update the local verify check

Fixes #11

Tests

  • go test -count=1 ./cmd/optiqor -run 'TestAnalyze_(OfflineShareWarnsAndSkipsUpload|OfflineEnvShareWarnsAndSkipsUpload|HelpDocumentsOfflineEnv)$'
  • go test -count=1 ./internal/... ./pkg/...
  • git diff --check

Note: make lint test could not be run on this Windows machine because make and golangci-lint are not installed; go test -race also requires cgo/gcc here. A full go test -count=1 ./... reaches existing golden-output mismatches caused by Windows path separators (<REPO>\... vs <REPO>/...).

@btwshivam
Copy link
Copy Markdown
Member

@aqilaziz Can you rebase and fix Ci.. meanwhile im reviewing your PR

@btwshivam
Copy link
Copy Markdown
Member

@aqilaziz Btw Welcome! and Thanks for PR!

@btwshivam
Copy link
Copy Markdown
Member

Hehe, I’d recommend switching to Linux. Trust me, you’ll never regret it 😄

@aqilaziz aqilaziz requested a review from btwshivam as a code owner May 15, 2026 10:13
@github-actions github-actions Bot added documentation Improvements or additions to documentation testing Test coverage and golden fixtures area/cli Cobra CLI commands and UX area/render Terminal renderer (TUI, HTML, JSON) size/M 51–200 lines labels May 15, 2026
@aqilaziz
Copy link
Copy Markdown
Author

Pushed follow-up fixes for the CI lint findings and resolved the merge conflict against current main without pulling unrelated workflow/history into this branch.

Verification run locally:

  • go test -count=1 ./cmd/optiqor -run TestAnalyze_(OfflineShareWarnsAndSkipsUpload|OfflineEnvShareWarnsAndSkipsUpload|HelpDocumentsOfflineEnv)$
  • go test -count=1 ./internal/... ./pkg/...
  • git diff --check

GitHub now reports the PR as mergeable; waiting for the queued PR checks to finish.

Copy link
Copy Markdown
Member

@btwshivam btwshivam left a comment

Choose a reason for hiding this comment

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

request changes: nest the share/offline branch, add the positive-path test, lock env precedence. also #20 fixes the same bug, only one should land.

Comment thread cmd/optiqor/main.go Outdated
return err
}
if shareFlag {
if shareFlag && offlineMode(offline) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

awkward as if A && B / else if A. nest it:

if shareFlag {
    if offlineMode(offline) {
        fmt.Fprintln(cmd.ErrOrStderr(), "warning: --share is ignored in --offline mode")
    } else {
        emitShareURL(cmd, rep)
    }
}

Comment thread cmd/optiqor/main.go
return s == rules.SeverityHigh || s == rules.SeverityMed || s == rules.SeverityLow
}

func offlineMode(flag bool) bool {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

worth a doc line saying this is the canonical egress gate. when watch or real audit add network calls they need to consult this too.

// offlineMode is the canonical egress gate. Any new network
// call in this binary MUST short-circuit when this returns true.
func offlineMode(flag bool) bool {

Comment thread cmd/optiqor/main_test.go
}
}

func TestAnalyze_OfflineShareWarnsAndSkipsUpload(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nothing here asserts --share actually fires emitShareURL when offline's off. add a sibling that captures stderr and greps for share URL:. that branch is now load-bearing.

Comment thread cmd/optiqor/main_test.go
}
}

func TestAnalyze_OfflineEnvShareWarnsAndSkipsUpload(t *testing.T) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

right now nothing proves env beats an explicit --offline=false. add a variant with --offline=false --share and OPTIQOR_OFFLINE=1 set, assert the warning still fires.

Signed-off-by: aqilaziz <gonzes7@gmail.com>
@aqilaziz
Copy link
Copy Markdown
Author

Follow-up pushed in 0272f41 addressing the review items:

  • nested the --share/offline branch for readability
  • documented offlineMode as the canonical egress gate
  • added a positive-path --share upload test
  • added coverage that OPTIQOR_OFFLINE=1 still wins over --offline=false
  • carried the README link fix so the markdown link check is green

CI is green now. I also tried to update/rebase the branch against latest main, but GitHub blocks this token from carrying the upstream .github/workflows/ci.yml change because it lacks workflow scope. The PR is still mergeable, but it may need a maintainer-side update branch/rebase if your branch protection requires it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli Cobra CLI commands and UX area/render Terminal renderer (TUI, HTML, JSON) documentation Improvements or additions to documentation size/M 51–200 lines testing Test coverage and golden fixtures

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix --offline flag: it is parsed but currently a no-op

2 participants