Commit Graph

37582 Commits

Author SHA1 Message Date
Jean-Hadrien Chabran
0fd6235fa4
chore(rel): prepare stitch graph for 5.6 (#64343)
The only manual action for bumping a minor but we'll get there :) 

## Test plan

CI
2024-08-07 19:25:15 +02:00
Jean-Hadrien Chabran
4591d989a6
chore(local): clear ambiguity in between sg version|live (#64122)
Context: As I was catching up with my Slack notifications, I spotted
this
[conversation](https://sourcegraph.slack.com/archives/C04MYFW01NV/p1721137862832899?thread_ts=1721136881.733869&cid=C04MYFW01NV)
and this PR is a 5m fix to avoid the problem to happen again.

What: If you haven't used `sg` in a while, it's easy to think that `sg
version` refers to the currently deployed Sourcegraph instance and not
the CLI. This commit adds a little preamble on stderr to not mess with
script usage while still reminding the user that it's the CLI version
that gets printed out.

Before: we printed the version without any context
After: we also print the following on stderr: `👉 Showing the current
version of the sg CLI, if you're looking for deployed Sourcegraph
instances version, please use `sg live` instead.`. Stderr so we don't
break things like `$(sg version)`.

Note: at a broader level, we should generalize this pattern, we don't
use too much `sg` raw output in scripts, but for the few places where
it's the case, it's a footgun.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

Locally tested + CI. 

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

- `sg version` explicitly mentions that it's the CLI version that's
printed out, not any instance version.

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-07 18:34:38 +02:00
Camden Cheek
993e732583
Svelte: enable toggle by default (#64340) 2024-08-07 15:38:25 +00:00
Jean-Hadrien Chabran
9f0e1e04b8
chore(local): improve runnable cmds preambles in sg start (#64339)
`sg start ...` commands have a preamble field to inform the user about
various things. Prior to this PR, they were rather easy to miss. Along
the way, I've fixed the printing so if there multiple lines of preamble,
they appear nicely.

This PR addresses that. 


<details><summary>before/after</summary>
<p>
<img
src="https://github.com/user-attachments/assets/22d94ebb-e247-4e4e-8dab-1f502f1e8b46"/>
<img
src="https://github.com/user-attachments/assets/7cbbf41b-a926-4ebd-9f6d-bbdd779cc8b4"/>
</p>
</details> 

## Test plan

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

Locally tested, see before/after.
2024-08-07 15:20:07 +00:00
Camden Cheek
3ff0f07646
Svelte: more welcome banner behavior updates (#64311)
This makes some requested changes to the welcome banner. 

Notably:
- We no longer show the dialog unless the user switches into the svelte
version from react
- We don't show the dialog on every switch
- The dialog is accessible in the React via the "Learn more" button in
the menu
- Copy is updated to be less verbose
- The request for feedback is only shown once when switching out of the
svelte webapp
2024-08-07 08:55:57 -06:00
William Bezuidenhout
61b41814bd
fix(sg): provide suggestions we fail to get local gcp account email address (#64325)
Part of https://github.com/sourcegraph/devx-support/issues/1142

If we fail to get the gcp address, provide steps the user can try to fix
it

![Screenshot 2024-08-07 at 10 14
00](https://github.com/user-attachments/assets/39e6fdcb-ee60-43b8-bdca-d28a9d210b2e)


## Test plan
Tested locally

## Changelog
sg - provide steps a user can follow if we fail to get the local gcp
email address
2024-08-07 14:02:30 +00:00
Varun Gandhi
e1e78988aa
chore: Add docs for RepoStore methods (#64283) 2024-08-07 21:27:37 +08:00
Felix Kling
e4e1f55026
fix(svelte): Properly redirect to cody marketing page (#64331)
Fixes srch-851

A consequence of https://github.com/sourcegraph/sourcegraph/pull/64272
is that redirecting to the cody marketing page on dotcom didn't work.
That's because `/cody` is not provided by the server as a known page.

A simple fix would be to mark the link as external, but we'd have to
keep in mind to do this in all places (present and future).

A more "central" fix is to add this page to a hardcoded list of known
pages that are not provided by the server.


## Test plan

Manual testing
2024-08-07 15:24:02 +02:00
Felix Kling
2e0a3ee92e
fix(svelte): Better preloading in file tree (#64327)
Currently the link element doesn't extend to the full width of the
sidebar. You can click outside of the actual text to navigate to the
file, but it won't be preloaded.

Now the link occupies the full width.

## Test plan

Manual testing.
2024-08-07 15:23:35 +02:00
Quinn Slack
f7d4517dbc
upgrade Cody Web, always create a new chat (#64334)
Incorporates https://github.com/sourcegraph/cody/pull/5129

## Test plan

Run in SvelteKit and non-SvelteKit. Ensure that the Cody standalone chat
and Cody sidebar chats work.
2024-08-07 13:23:25 +00:00
Felix Kling
ebaab129ee
feat(svelte): Add support for creating search jobs from search results (#64308)
Closes srch-838

This commit extends the search progress popover and adds the search jobs
section.

In the React version the UI for the popover differs slightly when search
jobs are enabled vs not enabled.

I decided to ignore the differences and only impolemented the style used
for the 'search jobs enabled' version, which makes the popover a bit
more compact.

The logic for validating and creating a search job is encapsulated in a
class which makes it easy to conditionally show the search jobs UI.

Additional changes:

- Skipped items is now a list and uses `<details>` elements which is
semantically more correct. We loose the styling of the chevron but I
think that's OK.
- LoadingSpinner was updated to work inline.
- Logging was fixed (?) in the React version to send the correct
meta-data.
- Added integration tests for the search job popover behavior

## Test plan

Integration tests and manual testing.
2024-08-07 14:25:35 +02:00
Varun Gandhi
93818e0d9b
fix: Try workaround for bad index choice when updating execution logs (#64328)
Under high contention, the updating of execution logs query:

```
UPDATE
  lsif_indexes
SET
  execution_logs = execution_logs || $1::json
WHERE
  id = $2
  AND worker_hostname = $3
  AND state = $4 RETURNING ARRAY_LENGTH(execution_logs, $5)
```

Was taking multiple seconds due to lock contention on the
lsif_indexes_state index.

![image](https://github.com/user-attachments/assets/be58bc97-0995-4909-a032-69084ad995c5)

Running `EXPLAIN ANALYZE` on Sourcegraph.com under lower contention uses
the primary key index on id, so we don't have an easy way to test the
high contention scenario. Try this alternate query form to see if that fixes the issue.
2024-08-07 13:22:15 +02:00
Michael Bahr
4d6e8949e8
fix(batches): don't request unnecessary info that's likely to cause GH errors (#64299)
Closes SRCH-802

After a long and unsuccessful hunt of eventual consistency errors, I
noticed that we don't need the GraphQL fragments that are causing
problems.

I introduced a simplified request, which succeeds reliably. What
customers should see now is one error (see second picture below), which
is followed by a retry, and then success.

Previously we've seen this error, sometimes less often, sometimes more,
but customers saw it so often that it caused their batch changes to
fail.

<img width="1042" alt="Screenshot 2024-08-06 at 14 02 00"
src="https://github.com/user-attachments/assets/c5a099da-d474-43db-ac12-ac7c4f22d4d3">

Customers may still see an initial error, which I've seen to reliably
disappear on the first retry. It should not be a problem

<img width="1039" alt="Screenshot 2024-08-06 at 14 02 48"
src="https://github.com/user-attachments/assets/99f278d4-4020-48ea-b4ac-32cbdfce455d">

## Test plan

Manual testing

## Changelog

- fix(batches): improve GitHub Apps integration reliability by
simplifying the data requested from GitHub
2024-08-07 10:47:37 +02:00
Christoph Hegemann
81fa144f4f
refactor: steps the usage cursor provenance state in a single place (#64321)
Adds a second function to determine the initial cursor based on the
requested provenances.

## Test plan
N/A
2024-08-07 10:39:12 +02:00
Naman Kumar
3efa77aad9
Center align Cody logo in Cody Web Sidebar (#64324)
Fixes Cody Logo alignment to center for both React & Svelte Cody Sidebar
header.

## Test plan

Before:
![CleanShot 2024-08-07 at 13 30
04@2x](https://github.com/user-attachments/assets/c1b8471d-3f25-4b75-bf54-888876578d63)

After:

![CleanShot 2024-08-07 at 13 30
19@2x](https://github.com/user-attachments/assets/483e1abd-ea6e-498b-8d98-6295a23f5cca)

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-07 09:21:57 +01:00
Christoph Hegemann
780b5dbbc4
chore: Move and clean up test code for syntactic usages (#64318)
Consolidates the two test helper/util modules, and moves one test file
to align with the file it's actually testing.

## Test plan

Tests continue to pass
2024-08-07 09:15:58 +01:00
Varun Gandhi
930033ca9b
chore: Replace QueuedCount -> CountByState with bitset parameter (#64302)
Previously, the QueuedCount method was confusing because:

1. By default, it actually returned the count for both the 'queued' and
   'errored' states (despite the name just have 'Queued').
2. There was an additional boolean flag for also returning entries in
    the 'processing' state, but reduced clarity at call-sites.

So I've changed the method to take a bitset instead, mirroring the
just-added Exists API, and renamed the method to a more
generic 'CountByState'.

While this does make call-sites a bit more verbose, I think the
clarity win makes the change an overall positive one.
2024-08-07 16:09:18 +08:00
Naman Kumar
6ee444656c
Fix Cody Web Svelte Sidebar (#64320)
Cody's Web Sidebar in Svelte is not following the theme when tested
locally.

This PR fixes that. I have tested this with multiple builds both with &
without the diff.

## Test plan

Before:

![image](https://github.com/user-attachments/assets/b2c669fa-a0a7-4dc7-9440-8fca7aa69fd5)

After:
![CleanShot 2024-08-07 at 12 20
19@2x](https://github.com/user-attachments/assets/66bda613-d811-47d0-b0c5-23707e60f875)


## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-07 07:27:23 +00:00
Christoph Hegemann
f1d5d779c3
refactor: handles Cursor uniformly over all usage provenances (#64319)
This change should not change any behaviour, but it prepares for syntactic/search-based pagination.

Both syntactic and search based usages now return a "NextCursor", which is `Some` if there are more results of their provenance to be had. For now they always return `None` which preserves the current behaviour. The logic in `root_resolver` implements a state machine that transitions the cursor through the provenances and makes sure to skip provenances if the cursor in the request starts a certain state.

## Test plan

Tests continue to pass, no behavioral changes
2024-08-07 08:26:31 +02:00
Naman Kumar
3680503eab
Update Cody Web to 0.3.7 (#64296)
closes:
https://linear.app/sourcegraph/issue/SRCH-821/context-is-not-being-fetched-on-vs-code-even-though-its-being-fetched

![CleanShot 2024-08-06 at 16 13
05@2x](https://github.com/user-attachments/assets/e338865c-5949-4b18-8e2c-41afcc4abc1b)

This PR updates Cody Web to 0.3.7. The latest version introduces the
following changes:
- Removes the Cody history panel and rather uses the tabs. (As updated
in latest version on Cody Web)
- Removes the `experimental.noodle` flag set to true. 
- Fixes the issue where the query for `getCodyContext` contained mention
chips text and was different from VS Code.

## Test plan

- visit /cody/chat

## Changelog
2024-08-07 10:27:17 +05:30
Bolaji Olajide
2e642bc85e
fix(bazel): surface error message when gazelle cant process glob expression (#64214)
Closes DINF-89

Gazelle sometimes have trouble processing glob expressions, and this
isn't reported as a failure even though it ultimately results in the
`BUILD.bazel` not being correctly updated.

## Test plan

* Manual testing

In `client/web/BUILD.bazel`, add a new `src` to the `web_lib` ts_project
target that includes a glob pattern.

```
...
ts_project(
    name = "web_lib",
    srcs = glob(["!src/playwright/*.spec.ts"]) + [
        "src/Index.tsx",
        "src/LegacyLayout.tsx",
        "src/LegacyRouteContext.tsx",
        "src/LegacySourcegraphWebApp.tsx",
        "src/PageError.tsx",
        "src/SearchQueryStateObserver.tsx",
        "src/SourcegraphWebApp.tsx",
...
```

When you run `go run ./dev/sg bazel configure`, the command should fail
with an error message instead of returning exit 0.

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

---------

Co-authored-by: Jean-Hadrien Chabran <jean-hadrien.chabran@sourcegraph.com>
2024-08-06 17:37:15 -05:00
Bolaji Olajide
4a5e1e450a
feat(sg): report user os information via analytics (#64280)
Closes DINF-193

![CleanShot 2024-08-05 at 21 28
37@2x](https://github.com/user-attachments/assets/34f121c5-5a85-456c-b12b-2f959573fcae)

OS information is now part of the `sg` analytics metadata.


## Test plan

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

Any `sg` operation now reports the os information.

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-06 17:31:50 -05:00
Felix Kling
02fb199189
chore(svelte): Add manual entries for repo sub pages to development proxy (#64313)
I noticed that non-svelte repo subpages haven't been redirected to the
React app in local development (it works as expected in production).

That's because the proxy doesn't know about them since they are not part
of `knownRoutes`.
We could update the server code to include those routes as well but that
seems heavey handed just to make local development work.

I think in this case it's fine to have manual entries for the handful of
repo subpages that have not been migrated to Svelte yet.

## Test plan

Manual testing.
2024-08-06 15:46:33 -06:00
Felix Kling
b6a25c8a11
fix(own): Prevent infinite UI update loop in own pages (#64312)
I noticed that my computer fans kept on spinning when visiting
https://sourcegraph.test:3443/github.com/sourcegraph/sourcegraph/-/own
and
https://sourcegraph.test:3443/github.com/sourcegraph/sourcegraph/-/own/edit.

Long story short because we are not memoizing the breadcrumbs we are in
an infinite update loop. The offending commit is
c42c57da1d.

## Test plan

Manual testing. Fans stopped spinning.
2024-08-06 22:34:05 +02:00
Chris Smith
582022d301
Return model IDs from GraphQL, not model Names (#64307)
::sigh:: the problem here is super in the weeds, but ultimately this
fixes a problem introduced when using AWS Bedrock and Sourcegraph
instances using the older style "completions" config.

## The problem

AWS Bedrock has some LLM model names that contain a colon, e.g.
`anthropic.claude-3-opus-20240229-v1:0`. Cody clients connecting to
Sourcegraph instances using the older style "completions" config will
obtain the available LLM models by using GraphGL.

So the Cody client would see that the chat model is
`anthropic.claude-3-opus-20240229-v1:0`.

However, under the hood, the Sourcegraph instance will convert the site
config into the newer `modelconfig` format. And during that conversion,
we use a _different value_ for the **model ID** than what is in the site
config. (The **model name** is what is sent to the LLM API, and is
unmodified. The model ID is a stable, unique identifier but is sanitized
so that it adheres to naming rules.)

Because of this, we have a problem.

When the Cody client makes a request to the HTTP completions API with
the model name of `anthropic.claude-3-opus-20240229-v1:0` or
`anthropic/anthropic.claude-3-opus-20240229-v1:0` it fails. Because
there is no model with ID `...v1:0`. (We only have the sanitized
version, `...v1_0`.)

## The fix

There were a few ways we could fix this, but this goes with just having
the GraphQL component return the model ID instead of the model name. So
that when the Cody client passes that model ID to the completions API,
everything works as it should.

And, practically speaking, for 99.9% of cases, the model name and model
ID will be identical. We only strip out non-URL safe characters and
colons, which usually aren't used in model names.

## Potential bugs

With this fix however, there is a specific combination of { client,
server, and model name } where things could in theory break.
Specifically:

Client | Server | Modelname | Works |
--- | --- | --- | --- | 
unaware-of-modelconfig | not-using-modelconfig | standard | 🟢 [1] |
aware-of-modelconfig | not-using-modelconfig | standard | 🟢 [1] |
unaware-of-modelconfig | using-modelconfig | standard | 🟢 [1] |
aware-of-modelconfig | using-modelconfig | standard | 🟢  [3] |
unaware-of-modelconfig | not-using-modelconfig | non-standard | 🔴 [2] |
aware-of-modelconfig | not-using-modelconfig | non-standard | 🔴 [2] |
unaware-of-modelconfig | using-modelconfig | non-standard | 🔴 [2] |
aware-of-modelconfig | using-modelconfig | non-standard | 🟢  [3] |

1. If the model name is something that doesn't require sanitization,
there is no problem. The model ID will be the same as the model name,
and things will work like they do today.
2. If the model name gets sanitized, then IFF the Cody client were to
make a decision based on that exact model name, it wouldn't work.
Because it would receive the sanitized name, and not the real one. As
long as the Cody client is only passing that model name onto the
Sourcegraph backend which will recognize the sanitized model name / ID,
all is well.
3. If the client and server are new, and using model config, then this
shouldn't be a problem because the client would use a different API to
fetch the Sourcegraph instance's supported models. And within the
client, natively refer to the model ID instead of the model name.

Fixes
[PRIME-464](https://linear.app/sourcegraph/issue/PRIME-464/aws-bedrock-x-completions-config-does-not-work-if-model-name-has-a).

## Test plan

Added some unit tests.



## Changelog

NA
2024-08-06 13:28:33 -07:00
Felix Kling
c414477bee
fix(svelte): Center file tree loading indicator (#64309)
We should probably redesign the whole loading state but this simple
change is still better than the current behavior.

| Before | After |
|--------|--------|
|
![2024-08-06_21-00_1](https://github.com/user-attachments/assets/015d47d3-9542-4d72-b422-56975723576c)
|
![2024-08-06_21-00](https://github.com/user-attachments/assets/0e667bc2-496e-4169-806d-b49757681673)
|

## Test plan

Manual testing.
2024-08-06 21:20:49 +02:00
Chris Smith
b0bb67b47c
Update the default Sourcegraph-supplied LLM models (#64281)
This PR sets the defaults for "Sourcegraph supplied LLM models". 

## When will these "defaults" be used?

These models will _only_ be used IFF the Sourcegraph instance is
_explicitly_ using the newer "modelConfiguration" site configuration
data. (And opts into using Sourcegraph-supplied LLM models.)

If the Sourcegraph instance is using the older "completions"
configuration blob, then _only_ the user-supplied models will be used.
(Or, based on the specific defaults defined in the code for the
completions provider.)

## What about Cody Free or Cody Pro?

😬 yeah, we're going to need to deal with that later. Currently
Sourcegraph.com is _not_ using the newer "modelConfiguration" site
configuration, and instead we have some hacks in the code to ignore the
internal modelconfig. See this "super-shady hack":

e5178a6bc0/cmd/frontend/internal/httpapi/completions/get_model.go (L425-L455)

So we are just erring on the side of having Cody Free / Cody Pro "do
whatever they do now", and this PR won't have any impact on that.

We _do_ want Sourcegraph.com to only return this data, but there are a
few things we need to get straightened out first. (e.g. Cody Gateway
being ware of mrefs, and having Cody Clients no longer using `dotcom.ts`
to hard-code Cody Pro LLM models.)

## What does this PR actually _do_?

1. It updates the code in `cmd/cody-gateway-config` so that it will
produce a new "supported-models.json" file.
2. I then ran the tool manually, the output of which was then written to
`internal/modelconfig/embedded/models.json`.
3. That's it.

For any Sourcegraph releases after this PR gets merged, the "Sourcegraph
supplied LLM models" will be the newer set defined in `models.json`.
(i.e. having these new defaults, and including
"fireworks::v1::starcoder".)

## Test plan

~~I tested things locally, and unfortunately it doesn't look like any
clients are filtering based on the model capabilities. So "StarCoder" is
showing up in the Cody Web UI, despite failing at runtime.~~

Update: This was a problem on my end. This isn't an issue.


## Changelog

NA?
2024-08-06 10:26:56 -07:00
Stefan Hengl
ee93777dd4
fix(search_jobs): fail validation for repo searches (#64300)
This closes a pretty big gap in the query validation for Search Jobs. We
don't support repo search yet and searcher returned errors during
execution, complaining about missing patterns. With this PR we fail
during validation so users cannot even create these kinds of jobs. See
new test cases.

## Test plan
Updated unit tests
2024-08-06 17:16:52 +02:00
Varun Gandhi
bf4eb26bdf
fix: Add Exists method to dbworker Store to avoid COUNT(*) (#64297)
Running `COUNT(*)` on hot tables like lsif_indexes on Sourcegraph.com
shows up on profiles when the number of executors is bumped to
30+, and when the table has 100K+ jobs. So avoid `COUNT(*)`
where possible.
2024-08-06 22:13:09 +08:00
Varun Gandhi
99f7d97dc6
chore: Switch over to fake RepoStore in codenav tests (#64284)
Reduce the exposed surface area with a smaller interface
minimalRepoStore, and make sure we're using fakes in the
tests which better document the intent, instead of using a
mock repo store. The fake makes sure that the methods
are mutually consistent, which is easier to do when working
with a smaller interface.
2024-08-06 22:09:43 +08:00
Petri-Johan Last
1cac35b246
Update wolfi hashes (#64289)
Ran `sg wolfi update-hashes`

## Test plan

Hashes updated.

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

---------

Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
2024-08-06 15:54:02 +02:00
Felix Kling
0959fbda1a
fix(svelte): Make /cody/dashboard work with the new web app (#64295)
Fixes srch-765

When navigating to `/cody/dashboard` and the new web app is enabled, the
user gets a "Not found" error. This doesn't happen in the React app.

The page doesn't exist in the new web app, hence the server should fall
back to the old web app but that doesn't happen.

Why? Because the server doesn't know about `/cody/dashboard` either. It
only exists in the React app.
Instead the server interprets this path as a (non-existing) repository
page. When the new web app is enabled, repository pages are handled by
the new web app, but since neither the repo nor the page exist in the
new web app, the aforementioned error is thrown.

Configuring this route on the server makes it so that the React app is
served instead.

## Test plan

Manual testing. Going to https://sourcegraph.test:3443/cody/dashboard
loads the React app.
2024-08-06 15:33:24 +02:00
Julie Tibshirani
958afb0936
Search: boost matches on quoted terms (#64298)
Follow up to #64207. In our old search semantics, quotes were
interpreted literally. So a query like `"sourcegraph"` would match only
strings like `fmt.Println("sourcegraph")`. Now, both single and double
quotes are used for escaping, and mean that the contents should be
searched exactly.

This PR makes sure to boost matches on quoted terms in result ranking.
This way, users familiar with the old syntax are more likely to find
what they're after.

## Test plan

Adapted unit tests. Re-tested all queries from #64207 manually, plus
these ones:
* `'sourcegraph'`
* `"sourcegraph"`
2024-08-06 15:55:24 +03:00
Erik Seliger
ff52b14dd1
chore: Remove unnecessary _ imports (#64158)
These imports don't seem to have side-effects so dropping them to keep the dependency graph simple.

Test plan: E2E CI still passes.
2024-08-06 13:28:29 +02:00
Erik Seliger
6b98c253ab
chore: Frontend does not need disk (#64273)
A long time ago, we dropped the requirement for frontend to have any
disk for caching. Our helm deployments use read-only rootFSes, so this
wouldn't even work.

This PR aims to make that clearer by removing some last remnants of
those times.

Test plan: Frontend starts locally and integration tests pass in CI.
2024-08-06 13:22:00 +02:00
Julie Tibshirani
f19af57fe4
Search: re-add support for 'lucky' patterntype (#64293)
In #64215, we removed support for smart search. We continued to allow
the `smart` search mode, but just execute with `precise` behavior.
However, we started to throw an error for `patterntype:lucky` (which is
the old way of specifying smart search). It turns out that `lucky` made
its way into some search links and settings, causing those searches to
fail.

This PR restores support for `lucky`, and remaps it to `standard`. This
preserves the semantics as much as possible (since smart search attempts
a 'standard' search as its first rule).

Closes SRCH-840
2024-08-06 14:04:09 +03:00
Varun Gandhi
8f058838ce
chore: Consolidate mocks for dbworker/store.Store type (#64294)
Let's not regenerate it 4 extra times -- it's already generated
once in a central dbworker/store/mocks package which we can reuse.
2024-08-06 18:40:25 +08:00
Felix Kling
e4a8ce52da
fix(svelte): Update top-level route list (#64272)
tl;dr: Everything is derived from `window.context.svelteKit.knownRoutes`

*buckle up*

### Context

After the new web app was enabled by default on dotcom I looked at
dotcom data in Sentry to see if there was anything out of the ordinary.
I noticed a high number of errors related to resolving repository
information. The most common non-existing repository that was reported
was `-/sign-out`.

Of course this shouldn't happen. `/-/sign-out` is the sign out URL and
shouldn't be interpreted as a repository.

Currently we prevent SvelteKit from interpreting specific paths as
repositories by using the `reporev` parameter validator:

```ts
// src/params/reporev.ts
const topLevelPaths = [
    'insights',
    'search-jobs',
    'saved-searches',
    // ... many more here
]

const topLevelPathRegex = new RegExp(`^(${topLevelPaths.join('|')})($|/)`)

// This ensures that we never consider paths containing /-/ and pointing
// to non-existing pages as repo name
export const match: ParamMatcher = param => {
    // Note: param doesn't have a leading slash
    return !topLevelPathRegex.test(param) && !param.includes('/-/')
}
```

`-/sign-out` was not in that list, including others which have been
added since this file was originally created.

Adding it would have been the simple solution but having to maintain
this list manually has always irked me. Now we have a better way...

### Production changes

#### Client side

It turns out we are already sending a list of known routes to the client
in `window.context.svelteKit.knownRoutes` to basically do the same
thing: test whether a given path is a page or a repository.

```ts
// src/lib/navigation.ts
let knownRoutesRegex: RegExp | undefined

function getKnownRoutesRegex(): RegExp {
    if (!knownRoutesRegex) {
        knownRoutesRegex = new RegExp(`(${window.context?.svelteKit?.knownRoutes?.join(')|(')})`)
    }
    return knownRoutesRegex
}

// ...

export function isRouteEnabled(pathname: string): boolean {
    let foundRoute: SvelteKitRoute | undefined
 
    // [...]

    if (foundRoute) {
        if (foundRoute.isRepoRoot) {
            // Check known routes to see if there is a more specific route than the repo root.
            // If yes then we should load the React app (if the more specific route was enabled
            // it would have been found above).
            return !getKnownRoutesRegex().test(pathname)
        }
        return true
    }

    return false
}
```

Why do we have the `reporev` validator and `isRouteEnabled`? They
basically do the same thing (check whether a path is a known page or a
repository) the first (`reporev`) is used by SvelteKit to determine
which route a path corresponds to (i.e. to navigate to the repository
page or whether the page doesn't exist) and the second one
(`isRouteEnabled`) is used after the route resolution but before route
loading. It's used to trigger a full page refresh to fetch the React
version if necessary.

Anyways, since we already have a list of known pages from the server,
the parameter validator should just use it too. Except it didn't work,
which made the following server side changes necessary.

#### Server

We register routes in multiple places. Right now `knownRoutes` is
populated from the router created in
`cmd/frontend/internal/app/ui/router.go`, but this does not include
`/-/sign-out`. This route (and others) are defined in
`cmd/frontend/internal/app/router/router.go` (I don't know what the
difference is). I extended the sveltekit route registration code so
that's possible to register routes from multiple routers.

I couldn't test it yet however because I currently can't get Sourcegraph
to run locally (Camden tested it; it works).

### Development mode changes

After the above changes, navigating to a React only page in development,
e.g. `/insights` would show a 'repo not found error' because
`window.context.svelteKit.knownRoutes` was empty in development. So
every non-existing page would be interpreted as missing repository.

Hardcoding a list of known pages *again* just for development seemed to
be a step backwards. So I spent quite a bit of time to find a way to
extract the JS context object from the HTML page returned by the origin
server and inject it into the HTML page generated by SvelteKit, similar
to how we do it for the React app.

Additionally the value of `window.context.svelteKit.knownRoutes` is now
used to setup the proxy to non-supported pages from the server, so we
don't have to maintain this regex anymore either:

```ts
 // Proxy requests to specific endpoints to a real Sourcegraph
 // instance.
 '^(/sign-(in|out)|/.assets|/-|/.api|/.auth|/search/stream|/users|/notebooks|/insights|/batch-changes|/contexts)|/-/(raw|own|code-graph|batch-changes|settings)(/|$)': { ... }
```

This means that requesting non-svelte pages will also return the
corresponding React version in development.


## Test plan

Manual testing.
2024-08-06 09:53:50 +00:00
Christoph Hegemann
4ebb805bd3
fix: uses the same base64 for decoding we use for encoding the UsageCursor (#64290)
At the moment we decode via the "Std" encoding, which expects padding
but we encode with "Raw" which doesn't add any.

## Test plan

Manual testing
2024-08-06 17:38:00 +08:00
Keegan Carruthers-Smith
c09552ed15
searcher: fix benchmarks (#64292)
Column helper now returns 0 based indexes. FilterTar became a required
function on diskcache.

Test Plan: go test -run '^$' -bench . ./cmd/searcher/internal/search

Fixes
https://linear.app/sourcegraph/issue/SPLF-183/benchmarks-in-searcher-broken
2024-08-06 11:33:52 +02:00
Stefan Hengl
155975259a
fix(search_jobs): progress reporting (#64287)
Relates to #64186

With this PR we only show `83 out of 120 tasks` if the search job is
currently processing. In all other states, we don't show this stat. This
is a consequence of the janitor job I recently added, because after
aggregation, this data is not available anymore. User's can still
inspect the logs and download results to get a detailed view of which
revisions were searched.

I also remove an unnecessary dependency of the download links on the job
state.

## Test plan:

I ran a search job locally and confirmed that the progress message is
only visible while the job is processing and that logs and downloads are
always available.

## Changelog
- Show detailed progress only while job is in status "processing"
- Remove dependency of download links on job state
2024-08-06 11:16:04 +02:00
Varun Gandhi
38633daef0
chore: Consolidate mocks for uploads's Store type (#64286)
Instead of re-generating and re-compiling the mocks 3 times,
consolidate them into a single storemocks package.

This should also provide better code navigation in the editor.
2024-08-06 10:15:17 +01:00
Varun Gandhi
224e23697d
chore: Reduce frequency of COUNT(*) on lsif_indexes (#64288)
Previously, for metrics reporting, we were querying the number of
queued+errored records every 5 seconds. For large queues +
heavy contention, this scan itself takes a few seconds, despite using
an index. Reduce the frequency of this scan as we
don't need updates to the queue size every 5 seconds.

## Test plan

Check that frequency of `COUNT(*)` is reduced on Sourcegraph.com once
this patch makes its way to Sourcegraph.com
2024-08-06 10:39:20 +02:00
Christoph Hegemann
e48368df53
Enable SCIP based APIs by default (#64285)
Closes
https://linear.app/sourcegraph/issue/GRAPH-784/default-scip-api-ff-to-on

Enable SCIP based APIs by default, as they're required for the web app
refresh.

## Test plan
Things have been going fine on Dotcom and S2
2024-08-06 06:12:30 +00:00
Stefan Hengl
737e460a64
chore(search): update logging of search durations (#64269)
The current logging is outdated. This PR is not a complete rewrite. It
tries to keep semantics mostly as-is but it is more generous when it
comes to what we log. (For example we didn't log `(AND foo bar)` before)

IMO this is a good compromise we can ship quickly and then take some
time to figure out how to distinguish suggestions, searches, code-intel
and whether it is a good idea to mix search types and result types.

Updates:
- Prefer to log result types, fall back to pattern type. (This is
largely the same logic as before but we don't bail for complex queries)
- Don't guess repo and file results types if not explicitly specified.
We loose a bit of information here but it keeps the code much cleaner.
- Allow "AND" and "OR" operators.

The updated test case gives a good overview of how we would log things
in the future.

Kept as-is:
- I left "new" and "legacy" logging in place. I am not sure how we use
the target stores right now so I wanted to keep this as-is for now.
However we should see if we can retire the legacy logging.
- The previous and current logic translates `type:file` queries to
pattern types. I guess this makes sense from the perspective of how
things are implemented in the backend.
- "type:path" is logged as "file".

## Test plan:
Updated unit test
2024-08-06 07:26:01 +02:00
Chris Smith
a310035006
Return 'sourcegraph' as the CodyLLMConfigurationResolver.Provider (#64276)
This PR fixes Cody autocomplete in some situations, fixing
[PRIME-426](https://linear.app/sourcegraph/issue/PRIME-426/autocomplete-completely-broken-in-main-with-and-sometimes-without-the).

Our story begins with this PR:
https://github.com/sourcegraph/sourcegraph/pull/63886. The PR updated
the `CodyLLMConfigurationResolver.Provider` GraphQL endpoint to no
longer return the "provider" that was put into the site configuration,
but to instead return the _display name_ of the provider, or if multiple
were configured the string "various".

```diff
- func (c *codyLLMConfigurationResolver) Provider() string {
- 	return string(c.config.Provider)
- }
+ func (c *codyLLMConfigurationResolver) Provider() string {
+	if len(r.modelconfig.Providers) != 1 {
+		return "various"
+	}
+	return r.modelconfig.Providers[0].DisplayName
+}
```

This change was wrong on several levels, and unfortunately stemmed from
the original author (me) not tracking down and understanding how the
GraphQL endpoint was actually used.

Once we discovered the problem, we quickly rectified this by changing
the behavior to the more correct version of returning the Provider ID of
the code completion model with
https://github.com/sourcegraph/sourcegraph/pull/64165:

```go
func (r *codyLLMConfigurationResolver) Provider() string {
	return string(r.modelconfig.DefaultModels.CodeCompletion.ProviderID())
}
```

However, after some more testing we discovered yet another edge case. We
didn't realize that the provider "sourcegraph" (which is how you
configure Sourcegraph to use Cody Gateway, using the older site config
method) was required in some scenarios on the Cody client.

So the new logic, of returning the Provider ID was incorrect. (Because
we report the _model_ provider, e.g. "anthropic". Not the _API_
provider, e.g. "sourcegraph"/"Cody Gateway".)

With this change, we should just have the behavior we had initially:
returning whatever the admin had configured in the
"completions.provider" section of the site config. If only the newer
modelconfig settings were used, we return "sourcegraph" if using Cody
Gatway. And if not, just return the Provider ID. (Though in some
situations even that will lead to incorrect results, because ultimately
we need to update the client here.)

## Test plan

I wasn't able to test this super-well manually, and am relying on
Stephen and Taras' knowledge of how the client uses this today.

## Changelog

NA
2024-08-05 19:15:11 -07:00
Ara
e0991a68ea
Improving Azure errors for customer containers (#64278)
Fixing the logging description for Containers

## Test plan
Tested locally with containers

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-06 01:19:09 +00:00
Jacob Pleiness
44869b9a5c
appliance(chore): Remove legacy maintenance API (#64282)
Appliance now uses the API defined in internal/appliance. Deleted files
were no longer uses and an artifact from porting code from the POC.

<!-- PR description tips:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e
-->

## Test plan

Unit tests covering API are already in place.

<!-- REQUIRED; info at
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->
2024-08-05 20:49:55 -04:00
Camden Cheek
b9823cc90b
Svelte: remove site admin gate on code intel preview (#64277)
When I added this, for some reason I thought it was site admin only. As
it turns out, it shouldn't be gated to site admins only, and it makes it
particularly annoying on dotcom.
2024-08-05 23:59:15 +00:00
Jason Hawk Harris
e5178a6bc0
Revert "[Svelte]: UI Updates for Perforce Depots and Git Repos" (#64275)
Reverts sourcegraph/sourcegraph#64014

We decided that including this in the August 7th release would be rushed
after diving deeper into the project. Reverting this in order to
re-write the functionality, especially the data loading components.

## Test Plan
- this is a revert PR. Everything will work as before.
2024-08-05 16:30:41 +00:00