Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 0 additions & 53 deletions internal/api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,65 +130,12 @@ func (c *Client) AnalyzeSidecars(ctx context.Context, zipPath, idempotencyKey st
return &ir, nil
}

// AnalyzeIncremental uploads a zip of changed files and requests an incremental
// graph update from the API. changedFiles is sent on every request (initial and
// retries) so the server always has the full context.
func (c *Client) AnalyzeIncremental(ctx context.Context, zipPath string, changedFiles []string, idempotencyKey string) (*SidecarIR, error) {
post := func() (*JobResponse, error) {
return c.postIncrementalZip(ctx, zipPath, changedFiles, idempotencyKey)
}
job, err := c.pollLoop(ctx, post)
if err != nil {
return nil, err
}

var ir SidecarIR
if err := json.Unmarshal(job.Result, &ir); err != nil {
return nil, fmt.Errorf("decode incremental sidecar result: %w", err)
}
return &ir, nil
}

// postZip sends the repository ZIP to the analyze endpoint and returns the
// raw job response (which may be pending, processing, or completed).
func (c *Client) postZip(ctx context.Context, zipPath, idempotencyKey string) (*JobResponse, error) {
return c.postZipTo(ctx, zipPath, idempotencyKey, analyzeEndpoint)
}

// postIncrementalZip builds a multipart form with both the ZIP and the
// changedFiles JSON array, then submits it to the analyze endpoint.
func (c *Client) postIncrementalZip(ctx context.Context, zipPath string, changedFiles []string, idempotencyKey string) (*JobResponse, error) {
f, err := os.Open(zipPath)
if err != nil {
return nil, err
}
defer f.Close()

var buf bytes.Buffer
mw := multipart.NewWriter(&buf)
fw, err := mw.CreateFormFile("file", filepath.Base(zipPath))
if err != nil {
return nil, err
}
if _, err = io.Copy(fw, f); err != nil {
return nil, err
}
changedJSON, err := json.Marshal(changedFiles)
if err != nil {
return nil, err
}
if err := mw.WriteField("changedFiles", string(changedJSON)); err != nil {
return nil, err
}
mw.Close()

var job JobResponse
if err := c.request(ctx, http.MethodPost, analyzeEndpoint, mw.FormDataContentType(), &buf, idempotencyKey, &job); err != nil {
return nil, err
}
return &job, nil
}

// deadCodeEndpoint is the API path for dead code analysis.
const deadCodeEndpoint = "/v1/analysis/dead-code"

Expand Down
8 changes: 4 additions & 4 deletions internal/files/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (d *Daemon) incrementalUpdate(ctx context.Context, changedFiles []string) {
}
defer os.Remove(zipPath)

ir, err := d.client.AnalyzeIncremental(ctx, zipPath, changedFiles, idemKey)
ir, err := d.client.AnalyzeSidecars(ctx, zipPath, "incremental-"+idemKey[:8])
if err != nil {
d.logf("Incremental API error: %v", err)
return
Expand Down Expand Up @@ -476,9 +476,9 @@ func (d *Daemon) mergeGraph(incremental *api.SidecarIR, changedFiles []string) {
keptRels = append(keptRels, newRels...)
d.ir.Graph.Relationships = keptRels

if len(incremental.Domains) > 0 {
d.ir.Domains = incremental.Domains
}
// Preserve domains from the last full generate. Incremental responses
// contain domains classified from only the changed files, which are
// incorrect for the repo as a whole. Domains only refresh on full generate.

if len(extRemap) > 0 {
d.logf("Resolved %d external references to internal nodes", len(extRemap))
Expand Down
21 changes: 21 additions & 0 deletions internal/files/daemon_export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package files

import "github.com/supermodeltools/cli/internal/api"

// NewTestDaemon creates a daemon preloaded with an existing SidecarIR for testing merge logic.
func NewTestDaemon(ir *api.SidecarIR) *Daemon {
return &Daemon{
ir: ir,
logf: func(string, ...interface{}) {},
}
}

// MergeGraph exposes mergeGraph for testing.
func (d *Daemon) MergeGraph(incremental *api.SidecarIR, changedFiles []string) {
d.mergeGraph(incremental, changedFiles)
}

// GetIR returns the current merged SidecarIR.
func (d *Daemon) GetIR() *api.SidecarIR {
return d.ir
}
Loading
Loading