Skip to content

fix(site): update useAgentLogs to make it more testable and add more tests #19126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d6e00c3
wip: commit progress on test update
Parkreiner May 23, 2025
43d0ca8
refactor: update useAgentLogs tests as unit tests
Parkreiner May 23, 2025
727bddd
docs: rewrite comment for clarity
Parkreiner May 23, 2025
d46d144
fix: remove unnecessary type
Parkreiner May 23, 2025
91a6fc1
fix: make sure logs have different timestamps
Parkreiner May 23, 2025
ecbe7b0
fix: add different dates to reduce risk of false positives
Parkreiner May 23, 2025
d13bcdc
Merge branch 'main' into mes/logs-flake
Parkreiner May 23, 2025
0f21097
Merge branch 'main' into mes/logs-flake
Parkreiner Aug 2, 2025
abd6553
refactor: decrease coupling
Parkreiner Aug 2, 2025
bade97a
wip: commit progress on updating flake
Parkreiner Aug 2, 2025
e11fefd
Merge branch 'mes/logs-flake' of https://github.com/coder/coder into …
Parkreiner Aug 2, 2025
bc3d095
fix: get all tests passing
Parkreiner Aug 2, 2025
550d09e
chore: add one more test case
Parkreiner Aug 2, 2025
cc7e632
fix: update type mismatches
Parkreiner Aug 2, 2025
79c7ffd
refactor: clean up some code
Parkreiner Aug 2, 2025
43a0d3a
fix: make testing boundaries more formal
Parkreiner Aug 2, 2025
982d3e1
fix: remove premature optimization
Parkreiner Aug 2, 2025
41c5a12
fix: update setup
Parkreiner Aug 4, 2025
42cb73b
fix: update state sync logic
Parkreiner Aug 4, 2025
3a5f7bb
Merge branch 'main' into mes/logs-flake
Parkreiner Aug 4, 2025
35a40df
fix: update wonky types
Parkreiner Aug 4, 2025
306dbc7
Merge branch 'main' into mes/logs-flake
Parkreiner Aug 4, 2025
f49e55a
Merge branch 'main' into mes/logs-flake
Parkreiner Aug 7, 2025
c2fc772
fix: update tests
Parkreiner Aug 7, 2025
2cabd85
fix: format
Parkreiner Aug 7, 2025
855f3ca
Merge branch 'main' into mes/logs-flake
Parkreiner Aug 9, 2025
453894b
fix: apply initial feedback
Parkreiner Aug 9, 2025
c9f2b12
wip: commit refactoring progress
Parkreiner Aug 9, 2025
80865fe
refactor: update assignment
Parkreiner Aug 9, 2025
f930b29
wip: prepare to change indents
Parkreiner Aug 9, 2025
a311ac9
fix: update keygen logic
Parkreiner Aug 9, 2025
5657536
chore: add basic overflow message
Parkreiner Aug 9, 2025
6547a2f
chore: swap to tailwind
Parkreiner Aug 9, 2025
c818aec
wip: commit progress
Parkreiner Aug 12, 2025
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
Prev Previous commit
Next Next commit
refactor: clean up some code
  • Loading branch information
Parkreiner committed Aug 2, 2025
commit 79c7ffdd7cd288b765ddf71283e7f1d7da924c09
19 changes: 10 additions & 9 deletions site/src/modules/resources/AgentRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
Template,
Workspace,
WorkspaceAgent,
WorkspaceAgentLog,
WorkspaceAgentMetadata,
} from "api/typesGenerated";
import { Button } from "components/Button/Button";
Expand Down Expand Up @@ -79,21 +80,21 @@ export const AgentRow: FC<AgentRowProps> = ({
const agentLogs = useAgentLogs(agent.id, showLogs);
const logListRef = useRef<List>(null);
const logListDivRef = useRef<HTMLDivElement>(null);
const startupLogs = useMemo(() => {
const allLogs = agentLogs || [];
Copy link
Member Author

Choose a reason for hiding this comment

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

agentLogs is no longer nullable, so a bunch of logic can be removed


const logs = [...allLogs];
if (agent.logs_overflowed) {
logs.push({
const startupLogs = useMemo<readonly WorkspaceAgentLog[]>(() => {
if (!agent.logs_overflowed) {
return agentLogs;
}
return [
...agentLogs,
{
Copy link
Member

Choose a reason for hiding this comment

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

also I know it was already like this, but is shoving a log entry on the end really the best way to do this?

this startupLogs value eventually gets passed to AgentLogs below. what if we just passed agentLogs in unmodified and added an overflowed prop that shows the warning?

id: -1,
level: "error",
output:
"Startup logs exceeded the max size of 1MB, and will not continue to be written to the database! Logs will continue to be written to the /tmp/coder-startup-script.log file in the workspace.",
created_at: new Date().toISOString(),
Copy link
Member

Choose a reason for hiding this comment

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

we're leaking in here. I feel like this should be...

Suggested change
created_at: new Date().toISOString(),
created_at: agentLogs.at(-1).created_at,

since that's probably more "correct" and deterministic

source_id: "",
});
}
return logs;
},
];
}, [agentLogs, agent.logs_overflowed]);
const [bottomOfLogs, setBottomOfLogs] = useState(true);

Expand Down
Loading