We know that in answers (and by extension, questions), adding a relevant link is acceptable as long as any affiliation is disclosed, otherwise it counts as spam.
This is true even if the username of the author of the post has the same name as the person that wrote the contents of the link (with the following assumption that they're the same person):
the disclosure must happen in the post itself; the author’s username or profile do not count.
However, comments look slightly different to questions and answers - the username is directly next to the comment itself and so, very hard to miss (while it's entirely possible to read a question or answer without noticing the author). In addition, comments have a much more limited space and including a disclosure could use up that space (although writing a second comment is hardly the end of the world).
There are links to e.g. scientific papers and code where the author(s) is/are prominently displayed on the linked-to page and the above assumption about the comment-author and the linked-to-page author being the same person is a very natural one.
So, for such links in a comment, when it is clear from the comment-author's username that they also wrote the contents of/are affiliated with the linked-to page, do they still need to disclose that they are an author of/affiliated with the link?