Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit700a00c

Browse files
committed
rewrite
1 parent5bac6ef commit700a00c

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

‎agent/agentcontainers/api.go

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ func (api *API) markDevcontainerDirty(configPath string, modifiedAt time.Time) {
988988
logger.Info(api.ctx,"marking devcontainer as dirty")
989989
dc.Dirty=true
990990
}
991-
ifapi.ignoredDevcontainers[dc.WorkspaceFolder] {
991+
if_,ok:=api.ignoredDevcontainers[dc.WorkspaceFolder];ok {
992992
logger.Debug(api.ctx,"clearing devcontainer ignored state")
993993
delete(api.ignoredDevcontainers,dc.WorkspaceFolder)// Allow re-reading config.
994994
}
@@ -997,37 +997,6 @@ func (api *API) markDevcontainerDirty(configPath string, modifiedAt time.Time) {
997997
}
998998
}
999999

1000-
// markDevcontainerIgnored marks a devcontainer as ignored. Must not be called
1001-
// with the API lock held.
1002-
func (api*API)markDevcontainerIgnored(ctx context.Context,dc codersdk.WorkspaceAgentDevcontainer,procsubAgentProcess)subAgentProcess {
1003-
logger:=api.logger.With(
1004-
slog.F("devcontainer_id",dc.ID),
1005-
slog.F("devcontainer_name",dc.Name),
1006-
slog.F("workspace_folder",dc.WorkspaceFolder),
1007-
slog.F("config_path",dc.ConfigPath),
1008-
)
1009-
1010-
// We only allow ignore to be set in the root customization layer to
1011-
// prevent weird interactions with devcontainer features.
1012-
logger.Debug(ctx,"marking devcontainer as ignored")
1013-
proc.stop()
1014-
ifproc.agent.ID!=uuid.Nil {
1015-
// If we stop the subagent, we also need to delete it.
1016-
client:=*api.subAgentClient.Load()
1017-
iferr:=client.Delete(ctx,proc.agent.ID);err!=nil {
1018-
api.logger.Error(ctx,"delete subagent failed",slog.Error(err),slog.F("subagent_id",proc.agent.ID))
1019-
}
1020-
}
1021-
// Reset agent and containerID to force config re-reading if ignore is toggled.
1022-
proc.agent=SubAgent{}
1023-
proc.containerID=""
1024-
api.mu.Lock()
1025-
api.ignoredDevcontainers[dc.WorkspaceFolder]=true
1026-
api.mu.Unlock()
1027-
1028-
returnproc
1029-
}
1030-
10311000
// cleanupSubAgents removes subagents that are no longer managed by
10321001
// this agent. This is usually only run at startup to ensure a clean
10331002
// slate. This method has an internal timeout to prevent blocking
@@ -1118,11 +1087,24 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
11181087
returnxerrors.Errorf("read devcontainer config: %w",err)
11191088
}
11201089

1121-
ifconfig.Configuration.Customizations.Coder.Ignore {
1122-
api.mu.Unlock()
1123-
proc=api.markDevcontainerIgnored(ctx,dc,proc)
1124-
api.mu.Lock()
1090+
ignore:=config.Configuration.Customizations.Coder.Ignore
1091+
ifignore {
1092+
proc.stop()
1093+
ifproc.agent.ID!=uuid.Nil {
1094+
// Unlock while doing the delete operation.
1095+
api.mu.Unlock()
1096+
client:=*api.subAgentClient.Load()
1097+
iferr:=client.Delete(ctx,proc.agent.ID);err!=nil {
1098+
api.mu.Lock()
1099+
returnxerrors.Errorf("delete subagent: %w",err)
1100+
}
1101+
api.mu.Lock()
1102+
}
1103+
// Reset agent and containerID to force config re-reading if ignore is toggled.
1104+
proc.agent=SubAgent{}
1105+
proc.containerID=""
11251106
api.injectedSubAgentProcs[dc.WorkspaceFolder]=proc
1107+
api.ignoredDevcontainers[dc.WorkspaceFolder]=ignore
11261108
returnnil
11271109
}
11281110
}
@@ -1165,7 +1147,11 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
11651147
ranSubAgent:=false
11661148

11671149
// Clean up if injection fails.
1150+
varignored,setIgnoredbool
11681151
deferfunc() {
1152+
ifsetIgnored {
1153+
api.ignoredDevcontainers[dc.WorkspaceFolder]=ignored
1154+
}
11691155
if!ranSubAgent {
11701156
proc.stop()
11711157
if!api.closed {
@@ -1219,7 +1205,6 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
12191205
}
12201206

12211207
var (
1222-
ignorebool
12231208
appsWithPossibleDuplicates []SubAgentApp
12241209
workspaceFolder=DevcontainerDefaultContainerWorkspaceFolder
12251210
)
@@ -1243,13 +1228,15 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
12431228
returnerr
12441229
}
12451230

1246-
ignore=config.Configuration.Customizations.Coder.Ignore
1247-
workspaceFolder=config.Workspace.WorkspaceFolder
1248-
1249-
ifignore {
1231+
// We only allowignoreto be set in the root customization layer to
1232+
// prevent weird interactions with devcontainer features.
1233+
ignored,setIgnored=config.Configuration.Customizations.Coder.Ignore,true
1234+
ifignored {
12501235
returnnil
12511236
}
12521237

1238+
workspaceFolder=config.Workspace.WorkspaceFolder
1239+
12531240
// NOTE(DanielleMaywood):
12541241
// We only want to take an agent name specified in the root customization layer.
12551242
// This restricts the ability for a feature to specify the agent name. We may revisit
@@ -1295,8 +1282,19 @@ func (api *API) maybeInjectSubAgentIntoContainerLocked(ctx context.Context, dc c
12951282
api.logger.Error(ctx,"unable to read devcontainer config",slog.Error(err))
12961283
}
12971284

1298-
ifignore {
1299-
proc=api.markDevcontainerIgnored(ctx,dc,proc)
1285+
ifignored {
1286+
proc.stop()
1287+
ifproc.agent.ID!=uuid.Nil {
1288+
// If we stop the subagent, we also need to delete it.
1289+
client:=*api.subAgentClient.Load()
1290+
iferr:=client.Delete(ctx,proc.agent.ID);err!=nil {
1291+
returnxerrors.Errorf("delete subagent: %w",err)
1292+
}
1293+
}
1294+
// Reset agent and containerID to force config re-reading if
1295+
// ignore is toggled.
1296+
proc.agent=SubAgent{}
1297+
proc.containerID=""
13001298
returnnil
13011299
}
13021300

‎agent/agentcontainers/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2220,7 +2220,7 @@ func TestAPI(t *testing.T) {
22202220

22212221
assert.Empty(t,response.Devcontainers,"devcontainer should be filtered out when ignore=true again")
22222222
assert.Len(t,response.Containers,1,"regular container should still be listed")
2223-
assert.Len(t,fakeSAC.deleted,1,"sub agent should be deleted when ignore=true")
2223+
require.Len(t,fakeSAC.deleted,1,"sub agent should be deleted when ignore=true")
22242224
assert.Equal(t,createdAgentID,fakeSAC.deleted[0],"the same sub agent that was created should be deleted")
22252225
})
22262226
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp